From dc15a213326156e79b225e2575d0b3ce364043bf Mon Sep 17 00:00:00 2001 From: Sergey Sova Date: Tue, 5 Jun 2018 03:42:00 +0300 Subject: [PATCH] feat(execute): change format Previous command executes: store.execute(command(args)) === result Now command execute with arguments: store.execute(command, args) === result --- README.md | 10 +++++----- index.js | 6 +++++- package-lock.json | 5 +++++ 3 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 package-lock.json diff --git a/README.md b/README.md index bde1394..a38c148 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/index.js b/index.js index 54a3fb6..5e35508 100644 --- a/index.js +++ b/index.js @@ -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, diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..799ec5a --- /dev/null +++ b/package-lock.json @@ -0,0 +1,5 @@ +{ + "name": "optice", + "version": "0.1.0", + "lockfileVersion": 1 +}