-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Store management with createStore
#71
Conversation
.scan((previousState, action) => { | ||
let updatedState; | ||
const d = new Date(); | ||
const prettyDate = `${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}.${d.getMilliseconds()}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember, you don't have zero-padded integers.
} | ||
|
||
// logger in non-production mode only | ||
if (process.env.NODE_ENV !== 'production') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this logic should go to the logger itself, or better yet, whenever you create an instance of the logger you could specify the environment(s) in which it should work?
Why? Because of this: nodejs/node#3104
Another way would be to cache that value at the beginning of the module. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mAiNiNfEcTiOn: I kept it like it was working before. The main reason is because of our production bundles.
When NODE_ENV === production
, the full code-block inside this if
would not end up in the bundle processed by Webpack (in our case, it is vendors.js
file).
If we want to check it in runtime instead, it means the logger specific code would have to be in the bundle all the time. Do we want that in this PR?
Please correct me if I understood your comment wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, clear then.
return this.cachedState; | ||
} | ||
|
||
dispatch = (action) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this action
the String
(e.g. 'MY_ACTION'
) or the Object
passed with the type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mAiNiNfEcTiOn: sorry for the confusion. I should add some docblocks soon.
Store.dispatch
can accept:
- a payload, like:
{type: 'DO_SOMETHING'}
, or - a function, like:
function (dispatch, getState, { app }) { aTimeConsumingPromise() .then(function () { dispatch({ type: 'DO_SOMETHING' }); }); }
It maintains the sync/async actions, just like how we support them now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
;) Sure... good good. That's ok then :) 👍
The couple of deleted test files, like appendAction, and async: why aren those not needed anymore? And just to make sure I understand correctly: instead of depending on |
@markvincze: they are deleted because they were middlewares for Redux, now they are supported directly via See these
|
@@ -18,7 +18,15 @@ class BaseStore { | |||
.scan((previousState, action) => { | |||
let updatedState; | |||
const d = new Date(); | |||
const prettyDate = `${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}.${d.getMilliseconds()}`; | |||
const prettyDate = [ | |||
_.padStart(d.getHours(), 2, 0), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-.-' One liners...:
((str) => '0'.repeat(Math.abs(str.length - 2)) + str)(d.getHours())
...
But what do I know? 😄
What's done
createStore
functionredux
~7kB
from~13kB
Preview
Both examples in the repo working, and here's a screenshot for Multiple Widgets: