-
Notifications
You must be signed in to change notification settings - Fork 1.7k
cache registry reverses in local storage #4182
Conversation
import Contracts from '~/contracts'; | ||
import subscribeToEvents from '~/util/subscribe-to-events'; | ||
|
||
import registryABI from '~/contracts/abi/registry.json'; | ||
|
||
import { setReverse, startCachingReverses } from './actions'; | ||
|
||
const read = (chain) => { | ||
const reverses = window.localStorage.getItem(`${chain}-registry-reverses`); |
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.
- Would prefer using
store
(i.e.import store from 'store';
) - Would prefer the @ngotchac introduced
_parity::
prefix (still need to migrate old) - Would prefer
::
seperators as per above convention - Would prefer
<prefix>::<type>::<subtype>
, i.e._partity::reverse::${chain}
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.
- 👍
2.-3. Is there a specific reason for this? the.
notation seems to be a de-facto standard. I agree with prefixing withparity
, but why_parity
? Does that help somehow, except worse readability?
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.
It is not meant to be read by humans. :)
I just want everything to align with our codebase de-facto standards we have in-place now. I don't think what we have is 100% perfect, but it also doesn't detract and is consistent at least in all the new code. A good step.
We already have a mix now of old that still needs to be migrated, I would not like to add another way of doing things and make things even worse.
logLevel
as an exception is tolerated since we can actually direct people to change manually in case of bugs and in this case since there is manual interaction it makes the simpler format better.
const read = (chain) => { | ||
const reverses = window.localStorage.getItem(`${chain}-registry-reverses`); | ||
const lastBlock = window.localStorage.getItem(`${chain}-registry-reverses-last-block`); | ||
if (!reverses || !lastBlock) { |
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.
OCD-related comment (plus I'm old) - some spacing between vars and action (i.e. blank line here) would be appreciated.
const reverses = getReverses(); | ||
const lastBlock = getLastBlock(); | ||
|
||
window.localStorage.setItem(`${chain}-registry-reverses`, JSON.stringify(reverses)); |
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.
Additional bonus for using store
(as commented above) - no need to manually strigify
break; | ||
case 'setReverse': | ||
write( | ||
() => store.getState().nodeStatus.netChain, |
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.
Why don't we just pass the values in as opposed to passing in a function that retrieves the values?
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.
Premature optimization. 😉 write
gets called quite often. For all past & new reverse events.
@@ -24,7 +24,7 @@ export default (state = initialState, action) => { | |||
return state; | |||
} | |||
|
|||
return { ...state, reverse: { | |||
return { reverse: { |
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.
Would prefer spacey blocks reverse on next line just aligning with what we have. (Plus each entry on it's own line)
const STORE_KEY = '_parity::reverses'; | ||
|
||
const read = (chain) => { | ||
const reverses = store.get(`${STORE_KEY}::${chain}::data`); |
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.
Would probably make sense to const-ify data
& lastBlock
since it is used in multiple places. (Not a crisis either way)
|
||
const read = (chain) => { | ||
const reverses = store.get(`${STORE_KEY}::${chain}::data`); | ||
const lastBlock = store.get(`${STORE_KEY}::${chain}::last-block`); |
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.
Prefer lastBlock
to last-block
. Rationale -
- First in with the keys we already have in storage
- Fits in with the fact that we do
camelCase
for identifiers & filenames globally
if (!reverses || !lastBlock) { | ||
return null; | ||
} | ||
return { reverses, lastBlock }; |
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.
Empty line before return.
@@ -91,6 +127,17 @@ export default (api) => (store) => { | |||
clearTimeout(timeout); | |||
} | |||
|
|||
write.flush(); | |||
|
|||
break; |
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.
No need for blank line before.
write.flush(); | ||
|
||
break; | ||
case 'setReverse': |
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.
Blank line before.
Couple of small style & naming niggles, otherwise looks ok. |
Part of #4096.
still to do: