redux-zero
Advanced tools
Comparing version 4.6.1 to 4.7.0
# Changelog | ||
### 4.7.0 | ||
- Add Vue.js bindings | ||
### 4.6.0 | ||
@@ -4,0 +8,0 @@ |
{ | ||
"name": "redux-zero", | ||
"version": "4.6.1", | ||
"version": "4.7.0", | ||
"description": "", | ||
@@ -14,4 +14,3 @@ "main": "dist/redux-zero.js", | ||
"format": "prettier --write --no-semi \"src/**/*.ts\" \"src/**/*.tsx\"", | ||
"check": | ||
"npm run compile && npm run format && npm run lint && npm run test", | ||
"check": "npm run compile && npm run format && npm run lint && npm run test", | ||
"clean": "rimraf dist coverage", | ||
@@ -35,2 +34,3 @@ "prebuild": "npm run check && npm run clean", | ||
"utils", | ||
"vue", | ||
"index.d.ts" | ||
@@ -44,8 +44,16 @@ ], | ||
"jest": { | ||
"moduleFileExtensions": ["ts", "tsx", "js"], | ||
"setupFiles": ["<rootDir>/config/testSetup.js"], | ||
"moduleFileExtensions": [ | ||
"ts", | ||
"tsx", | ||
"js" | ||
], | ||
"setupFiles": [ | ||
"<rootDir>/config/testSetup.js" | ||
], | ||
"transform": { | ||
"^.+\\.(ts|tsx)$": "<rootDir>/config/preprocessor.js" | ||
}, | ||
"testMatch": ["<rootDir>/src/**/*.spec.(ts|tsx)"] | ||
"testMatch": [ | ||
"<rootDir>/src/**/*.spec.(ts|tsx)" | ||
] | ||
}, | ||
@@ -73,3 +81,4 @@ "devDependencies": { | ||
"tslint": "^5.7.0", | ||
"typescript": "2.5.3" | ||
"typescript": "2.5.3", | ||
"vue": "2.5.9" | ||
}, | ||
@@ -76,0 +85,0 @@ "keywords": [ |
@@ -23,2 +23,3 @@ <h1 align="center"> | ||
- [Example](#example) | ||
- [Async](#async) | ||
- [Middleware](#middleware) | ||
@@ -151,3 +152,52 @@ - [Inspiration](#inspiration) | ||
- [Svelte](https://github.com/concretesolutions/redux-zero/tree/master/examples/svelte/counter) | ||
- [Vue](https://github.com/concretesolutions/redux-zero/tree/master/examples/vue/counter) | ||
## Async | ||
Async actions in Redux Zero are almost as simple as sync ones. Here's an example: | ||
```js | ||
const mapActions = ({ setState }) => ({ | ||
getTodos() { | ||
setState({ loading: true }); | ||
return client.get("/todos") | ||
.then(payload => ({ payload, loading: false })) | ||
.catch(error => ({ error, loading: false })) | ||
} | ||
}); | ||
``` | ||
They're still pure functions. You'll need to invoke `setState` if you have a loading status. But at the end, it's the same, just return whatever the updated state that you want. | ||
And here's how easy it is to test this: | ||
```js | ||
describe("todo actions", () => { | ||
let actions, store, listener, unsubscribe; | ||
beforeEach(() => { | ||
store = createStore(); | ||
actions = getActions(store); | ||
listener = jest.fn(); | ||
unsubscribe = store.subscribe(listener); | ||
}); | ||
it("should fetch todos", () => { | ||
nock("http://someapi.com/") | ||
.get("/todos") | ||
.reply(200, { id: 1, title: "test stuff" }); | ||
return actions.getTodos().then(() => { | ||
const [LOADING_STATE, SUCCESS_STATE] = listener.mock.calls.map( | ||
([call]) => call | ||
); | ||
expect(LOADING_STATE.loading).toBe(true); | ||
expect(SUCCESS_STATE.payload).toEqual({ id: 1, title: "test stuff" }); | ||
expect(SUCCESS_STATE.loading).toBe(false); | ||
}); | ||
}); | ||
}); | ||
``` | ||
## Middleware | ||
@@ -154,0 +204,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
93609
73
795
242
22