Skip to content

Commit

Permalink
feat: Update packages, fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
andreidmt committed Feb 24, 2021
1 parent dbaa914 commit ec51b68
Show file tree
Hide file tree
Showing 22 changed files with 2,170 additions and 1,231 deletions.
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
}
},
"rules": {
// disable until upstream issues fixed
"jsdoc/check-line-alignment": "off",

"newline-after-var": "off"
},
}
9 changes: 3 additions & 6 deletions .nycrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
"functions": 100,
"branches": 100,
"include": [
"src/**/*.js"
"dist/**/*.js"
],
"exclude": [
"src/**/*.test.js",
"src/**/*.bench.js"
],
"require": [
"@babel/register"
"dist/**/*.test.js",
"dist/**/*.bench.js"
],
"reporter": [],
"cache": true,
Expand Down
3,175 changes: 2,057 additions & 1,118 deletions package-lock.json

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,48 +35,48 @@
"lint:md": "markdownlint *.md",
"lint": "npm run lint:md && npm run lint:js",
"----TEST": "",
"test": "tape -r @babel/register 'src/*.test.js' 'src/**/*.test.js' | tap-nirvana",
"pretest": "npm run build",
"test": "tape 'dist/*.test.js' 'dist/**/*.test.js' | tap-nirvana",
"tdd": "nodemon --watch src --exec \"npm run test\"",
"coverage:report": "NODE_ENV=test nyc npm test && nyc report --reporter=html",
"coverage": "NODE_ENV=test nyc npm test && nyc report --reporter=text-lcov | coveralls"
},
"dependencies": {
"@asd14/m": "^4.7.1",
"@babel/runtime-corejs3": "^7.12.13",
"core-js": "^3.8.3",
"regenerator-runtime": "^0.13.7",
"@asd14/m": "^5.0.0",
"@babel/runtime-corejs3": "^7.13.7",
"socket.io-client": "^3.1.1"
},
"devDependencies": {
"@asd14/eslint-config": "^5.24.0",
"@babel/cli": "^7.12.13",
"@babel/core": "^7.12.13",
"@babel/plugin-transform-runtime": "^7.12.15",
"@babel/preset-env": "^7.12.13",
"@babel/register": "^7.12.13",
"@asd14/eslint-config": "^5.28.1",
"@babel/cli": "^7.13.0",
"@babel/core": "^7.13.1",
"@babel/plugin-transform-runtime": "^7.13.7",
"@babel/preset-env": "^7.13.5",
"@babel/register": "^7.13.0",
"babel-eslint": "^10.1.0",
"core-js": "^3.9.0",
"coveralls": "^3.1.0",
"eslint": "^7.19.0",
"eslint-config-prettier": "^7.2.0",
"eslint": "^7.20.0",
"eslint-config-prettier": "^8.0.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsdoc": "^31.6.1",
"eslint-plugin-jsdoc": "^32.2.0",
"eslint-plugin-json": "^2.1.2",
"eslint-plugin-no-inferred-method-name": "^2.0.0",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-unicorn": "^28.0.0",
"eslint-plugin-promise": "^4.3.1",
"eslint-plugin-unicorn": "^28.0.2",
"markdownlint-cli": "^0.26.0",
"nodemon": "^2.0.7",
"npm-check": "^5.9.2",
"nyc": "^15.1.0",
"prettier": "^2.2.1",
"redux": "^4.0.5",
"semantic-release": "^17.3.8",
"semantic-release": "^17.3.9",
"socket.io": "^3.1.1",
"tap-nirvana": "^1.1.0",
"tape": "^5.1.1"
"tape": "^5.2.0"
},
"peerDependencies": {
"redux": "4.x"
"redux": "^4.x"
}
}
12 changes: 6 additions & 6 deletions src/create/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ const debug = require("debug")("JustAList:CreateAction")
/**
* Call list.create method to add result to slice.items
*
* @param {string} listName Slice name - for error messages
* @param {Function} dispatch Redux dispatch
* @param {Function} api API method
* @param {Function} onChange Appy on items array before changing state
* @param {string} listName Slice name - for error messages
* @param {Function} dispatch Redux dispatch
* @param {Function} api API method
* @param {Function} onChange Appy on items array before changing state
*
* @param {Object} data Model data
* @param {Array} rest Other paramaters passed when calling list.create
* @param {Object} data Model data
* @param {Array} rest Other paramaters passed when calling list.create
*
* @returns {Promise<Object<error, result>>}
*/
Expand Down
2 changes: 1 addition & 1 deletion src/create/create.reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const endReducer = (state, { listName, items = [], onChange = i }) => {
// reset error after successfull action
errors: {
...state.errors,
create: null,
create: undefined,
},
creating: [],
}
Expand Down
2 changes: 1 addition & 1 deletion src/create/tests/error.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ test("Create - error", async t => {

t.equals(
createError,
null,
undefined,
"State error is set to null after successfull create"
)

Expand Down
59 changes: 29 additions & 30 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ const collections = Object.create(null)
/**
* Construct a set of actions and reducers to manage a state slice as an array
*
* @param {string} name Unique list name
* @param {Function} onChange Function triggered on every list change
* @param {string} name Unique list name
* @param {Function} onChange Function triggered on every list change
*
* @returns {Object}
*/
Expand Down Expand Up @@ -77,7 +77,7 @@ const buildList = ({
collections[name] = true

let props = {
dispatch: null,
dispatch: undefined,
createHasDispatchStart: true,
createHasDispatchEnd: true,
readHasDispatchStart: true,
Expand Down Expand Up @@ -107,6 +107,31 @@ const buildList = ({
const removeEnd = `${name}_REMOVE_END`
const removeError = `${name}_REMOVE_ERROR`

const defaultState = {
listName: name,
items: [],
optimistItems: [],
creating: [],
reading: undefined,
updating: [],
removing: [],

errors: {
read: undefined,
readOne: undefined,
create: undefined,
update: undefined,
remove: undefined,
},

loadDate: undefined,
isCreating: false,
isLoading: false,
isLoadingOne: false,
isUpdating: false,
isRemoving: false,
}

return {
name,

Expand Down Expand Up @@ -284,33 +309,7 @@ const buildList = ({
return Promise.resolve([])
},

reducer: (
state = {
listName: name,
items: [],
optimistItems: [],
creating: [],
reading: null,
updating: [],
removing: [],

errors: {
read: null,
readOne: null,
create: null,
update: null,
remove: null,
},

loadDate: null,
isCreating: false,
isLoading: false,
isLoadingOne: false,
isUpdating: false,
isRemoving: false,
},
{ type, payload }
) => {
reducer: (state = defaultState, { type, payload }) => {
switch (type) {
// Create
case createStart:
Expand Down
9 changes: 5 additions & 4 deletions src/lib/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import isDeepEqual from "fast-deep-equal"
* .then(...)
* .catch(...)
*
* @returns {Object<enqueue, dequeue>}
* @returns {{enqueue, dequeue}}
*/
export const buildQueue = () => {
const jobsList = []
Expand All @@ -31,8 +31,9 @@ export const buildQueue = () => {
return runningJob.fnPromise
}

let deferredResolve = null
let deferredReject = null
let deferredResolve
let deferredReject

const fnResultPromise = new Promise((resolve, reject) => {
deferredResolve = resolve
deferredReject = reject
Expand Down Expand Up @@ -63,7 +64,7 @@ export const buildQueue = () => {
const shouldStartRunningJobs = !isProcessing && !isEmpty(jobsList)

if (!shouldStartRunningJobs) {
return undefined
return
}

const { fn, args, onResolve, onReject } = last(jobsList)
Expand Down
4 changes: 2 additions & 2 deletions src/lib/queue.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ test("Promise Queue - Promise based unique elements queue", t => {
const queue = buildQueue()

let findCountBatch1 = 0
let findDateBatch1 = null
let findDateBatch1
let findCountBatch2 = 0
let findDateBatch2 = null
let findDateBatch2

const jobs = [
// add job with same arguments
Expand Down
18 changes: 9 additions & 9 deletions src/read-one/read-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { hasKey, isEmpty } from "@asd14/m"
/**
* Call list.readOne method to add/update item in slice.items
*
* @param {string} listName Slice name - for error messages
* @param {Function} dispatch Redux dispatch
* @param {Function} api API method
* @param {Function} onChange Appy on items array before changing state
* @param {string} listName Slice name - for error messages
* @param {Function} dispatch Redux dispatch
* @param {Function} api API method
* @param {Function} onChange Appy on items array before changing state
*
* @param {string|number} id Id of item to update or add
* @param {Array} rest Other paramaters passed when calling list instance .readOne
* @param {string|number} id Id of item to update or add
* @param {Array} rest Other paramaters passed when calling list instance .readOne
*
* @returns {Promise<Object<error, result>>}
* @returns {Promise<{error, result}>}
*/
export const readOneAction = ({
listName,
Expand All @@ -22,7 +22,7 @@ export const readOneAction = ({
hasDispatchStart,
hasDispatchEnd,
onChange,
}) => (id, ...args) => {
}) => (id, ...params) => {
if (isEmpty(id)) {
throw new TypeError(
`JustAList: "${listName}".readOne ID param missing. Expected something, got "${JSON.stringify(
Expand All @@ -39,7 +39,7 @@ export const readOneAction = ({
}

return Promise.resolve()
.then(() => api(id, ...args))
.then(() => api(id, ...params))
.then(result => {
if (hasDispatchEnd) {
dispatch({
Expand Down
6 changes: 3 additions & 3 deletions src/read-one/read-one.reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export const endReducer = (state, { item, onChange = i }) => ({
// reset error after successfull action
errors: {
...state.errors,
readOne: null,
readOne: undefined,
},
reading: null,
reading: undefined,
})

export const errorReducer = (state, error) => ({
Expand All @@ -36,5 +36,5 @@ export const errorReducer = (state, error) => ({
...state.errors,
readOne: error,
},
reading: null,
reading: undefined,
})
2 changes: 1 addition & 1 deletion src/read-one/tests/error.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ test("ReadOne - error", async t => {

t.equals(
todos.selector(store.getState()).error("readOne"),
null,
undefined,
"State error is set to null after successfull readOne"
)

Expand Down
14 changes: 7 additions & 7 deletions src/read/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ const debug = require("debug")("JustAList:ReadAction")
/**
* Call list.read method to set slice.items array
*
* @param {Function} dispatch Redux dispatch
* @param {Function} api API method
* @param {Function} onChange Appy on items array before changing state
* @param {Function} dispatch Redux dispatch
* @param {Function} api API method
* @param {Function} onChange Appy on items array before changing state
*
* @param {Object} query Control/Filter attributes
* @param {boolean} opt.shouldClear If true, method result will replace existing items. Otherwise, merge both arrays by id
* @param {Object} opt.rest Other options passed when calling list instance .read
* @param {Object} query Control/Filter attributes
* @param {boolean} opt.shouldClear If true, method result will replace existing items. Otherwise, merge both arrays by id
* @param {Object} opt.rest Other options passed when calling list instance .read
*
* @returns {Promise<Object<error, result>>}
* @returns {Promise<{error, result}>}
*/
export const readAction = ({
listName,
Expand Down
2 changes: 1 addition & 1 deletion src/read/read.reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const endReducer = (
// reset error after successfull action
errors: {
...state.errors,
read: null,
read: undefined,
},
loadDate: new Date(),
isLoading: false,
Expand Down
2 changes: 1 addition & 1 deletion src/read/tests/error.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ test("Read - error", async t => {

t.equals(
todos.selector(store.getState()).error("read"),
null,
undefined,
"State error is set to null after successfull read"
)

Expand Down
14 changes: 7 additions & 7 deletions src/remove/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { isEmpty, get } from "@asd14/m"
/**
* Call list.remove method to remove item from slice.items
*
* @param {string} listName Slice name - for error messages
* @param {Function} dispatch Redux dispatch
* @param {Function} api API method
* @param {Function} onChange Appy on items array before changing state
* @param {string} listName Slice name - for error messages
* @param {Function} dispatch Redux dispatch
* @param {Function} api API method
* @param {Function} onChange Appy on items array before changing state
*
* @param {string|number} id Id of item to delete
* @param {Array} rest Other paramaters passed when calling list instance .remove
* @param {string|number} id Id of item to delete
* @param {Array} rest Other paramaters passed when calling list instance .remove
*
* @returns {Promise<Object<error, result>>}
* @returns {Promise<{error, result}>}
*/
export const removeAction = ({
listName,
Expand Down
Loading

0 comments on commit ec51b68

Please sign in to comment.