developit / developit/unistore

Show how to reuse actions within actions in docs?

Open
#75 4 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
JavaScript
Stars
2.8k
Forks
134
PR merge metrics
No merged PRs in 30d

Description

This works... maybe worth adding to the readme.
```js
// If actions is a function, it gets passed the store:
let actions = store => ({
// Actions can just return a state update:
increment(state) {
return { count: state.count + 1 };
},
// The above example as an Arrow Function:
increment2: ({ count }) => ({ count: count + 1 }),

// Async actions are actions that call store.setState():
incrementAsync(state) {
store.setState(this.increment(state));
setTimeout(() => {
store.setState({ count: store.getState().count + 1 });
}, 1000);
},
});
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.