Skip to content

Commit c3c483b

Browse files
committed
Implement extra arguments functionality
1 parent e856053 commit c3c483b

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ Creates a new store, which is a tiny evented state container.
191191
**Parameters**
192192

193193
- `state` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional initial state (optional, default `{}`)
194+
- `extraArgs`
194195

195196
**Examples**
196197

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface Store<K> {
2020
getState(): K;
2121
}
2222

23-
export default function createStore<K>(state?: K): Store<K>;
23+
export default function createStore<K>(state?: K, extraArgs?: any[] | any): Store<K>;
2424

2525
export interface ActionMap<K> {
2626
[actionName: string]: ActionCreator<K>;

src/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { assign } from './util';
1111
* store.setState({ a: 'b' }); // logs { a: 'b' }
1212
* store.setState({ c: 'd' }); // logs { a: 'b', c: 'd' }
1313
*/
14-
export default function createStore(state) {
14+
export default function createStore(state, extraArgs) {
1515
let listeners = [];
1616
state = state || {};
1717

@@ -52,7 +52,8 @@ export default function createStore(state) {
5252
function apply(result) {
5353
setState(result, false, action);
5454
}
55-
let ret = (action.action || action)(state, this);
55+
let args = [state, this];
56+
let ret = (action.action || action).apply(null, extraArgs ? args.concat(extraArgs) : args);
5657
if (ret != null) {
5758
if (ret.then) return ret.then(apply);
5859
return apply(ret);

0 commit comments

Comments
 (0)