-
Notifications
You must be signed in to change notification settings - Fork 180
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
Apply Partial Update to Virtual Stores #100
Conversation
Patch content script state instead of always replacing
}); | ||
let prevState = store.getState(); | ||
|
||
const patchState = () => { |
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.
This is where I was getting things wrong in my head. I like how you're doing the shallow diffing on the background page so the content script doesn't have to check equality at all (since all things serialized down will be new). Good shit. I need to make sure to grab a cup of ☕️ before talking in GH issues. :-P
src/wrap-store/wrapStore.js
Outdated
type: PATCH_STATE_TYPE, | ||
payload: diff, | ||
}); | ||
} | ||
}; | ||
|
||
// Send new state down connected port on every redux store state change |
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.
Can we change this comment to read // Send patched state down...?
test/shallowDiff.js
Outdated
@@ -0,0 +1,39 @@ | |||
// import should from 'should'; |
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.
Nix
src/wrap-store/shallowDiff.js
Outdated
@@ -0,0 +1,36 @@ | |||
const STATUS_UPDATED = 'updated'; |
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.
Love this direction. Let's put these in a shared src/constants
file and reference them here and in Store.js
above.
src/store/Store.js
Outdated
const state = Object.assign({}, this.state); | ||
|
||
difference.forEach(({change, key, value}) => { | ||
if (change === 'updated') { |
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.
Love this. I like what you did before with the switch/case ladder - mind doing that here?
// send initial state | ||
sendState(); | ||
// Send store's initial state through port | ||
port.postMessage({ |
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.
Nice. Thanks for the cleanup by removing sendState
!
test/shallowDiff.js
Outdated
{ | ||
key: 'a', | ||
value: 2, | ||
change: 'updated', |
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.
Loving these tests. When you extract out that constants file, could you reference the constants here as well?
@vhmth Great feedback! I'm very glad you like the change. Please let me know if there is anything else I can do. |
@tshaddix after you leave your feedback, I'll integrate into the Loom chrome extension repo locally to test out and see if there are any hiccups. I would say this is probably good to merge before then if we can get a more trivial example verified working. |
@vhmth @jdolle Looking through this, this looks good to me. I do have some clarifying questions on the "root" problem we are trying to solve. Consider it devil's advocate and due diligence:
I would feel really confident in this change if we had some quantified proof of the performance issue. That said, I really don't see this change as having an earth shattering impact on perf either. So then we go back to "this brings us closer to Redux" which is true. I'm happy to move forward with testing it in Loom's extension, @vhmth . We won't be able to do that at GG right now, I'm afraid, or I would offer. |
@tshaddix I am new to browser extensions and haven't done any performance tests, so I can't quantify the gains. It seems logical that copying less data over the messaging API would improve performance, but I think the major performance gain will be because of the simplification to prop comparisons. Overriding the entire state every time causes components, that might not otherwise, to be flagged as dirty and therefore re-render. |
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.
@vhmth Alrighty - let's move this forward! |
@vhmth I don't believe this warrants a |
Rather than replacing the entire state on content scripts every time a change occurs, this change will create
patch
messages, containing only the updated fields. This has a number of benefits.Resolves #98