Closed rpominov closed 9 years ago
Currently we have following API:
// Define: let myActionCreator = (fluce) => { return (some, args) => { fluce.dispatch('actionName', payload); } }; // Register: const fluce = createFluce(); fluce.addActionCreator('actionCreatorName', myActionCreator); // Call: fluce.actions.actionCreatorName(some, args);
Wouldn't it be better if we simply didn't have any API:
// Define: function myActionCreator(fluce, some, args) { fluce.dispatch('actionName', payload); } // Call: myActionCreator(fluce, some, args);
The only disadvantage of removing the API is that with API programmer can stash some action related state in the closure, for instance:
let refreshFoo = (fluce) => { let latestRequest; return () => { fluce.dispatch('refreshFooStart'); if (latestRequest !== undefined) { latestRequest.cancel(); } latestRequest = myApi.getLatestFoo((foo) => { fluce.dispatch('refreshFooSuccess', foo); latestRequest = undefined; }) } };
This is a rare use case, and programmer will have following options:
fluce
fluce.__refreshFooLatestRequest = ...
fluce.dispatch('refreshFooStart', cancelableRequest)
// foo-actions.js let latestRefreshRequest; export refreshFoo(fluce) { /*...*/ }
Related: #6
Currently we have following API:
Wouldn't it be better if we simply didn't have any API:
The only disadvantage of removing the API is that with API programmer can stash some action related state in the closure, for instance:
This is a rare use case, and programmer will have following options:
fluce
instance e.g.,fluce.__refreshFooLatestRequest = ...
fluce.dispatch('refreshFooStart', cancelableRequest)
Related: #6