Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
feat(execute): change format
Browse files Browse the repository at this point in the history
Previous command executes: store.execute(command(args)) === result
Now command execute with arguments: store.execute(command, args) === result
  • Loading branch information
Sergey Sova committed Jun 5, 2018
1 parent 19ad9b8 commit dc15a21
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,20 @@ Create new store object.
#### `Store.execute`

```
store.execute(command): result
store.execute(command: Function, ...args: any[]): result
```

Run command function with store methods `({ getState, setState, updateState, readState, execute })`.
Run command function with store methods `({ getState, setState, updateState, readState, execute })` and passed arguments.
Immediatly return result of command.

```js
const command = ({ getState, setState, updateState, readState, execute }) => {
const command = (a, b) => ({ updateState, readState, execute }) => {
// read, update state
// or execute another command
return 1
return 1 + a + b
}

store.execute(command) === 1
store.execute(command, 2, 1) === 4
```

#### `Store.getState`
Expand Down
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ const createStore = (initialState) => {
const readState = (lens) =>
L.view(getState(), lens)

const execute = (command) => command({ getState, setState, updateState, readState, execute })
const execute = (command, ...args) => command(...args)({
updateState,
readState,
execute
});

return {
execute,
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dc15a21

Please sign in to comment.