SplitProvider - Functional and aware of config changes#2
SplitProvider - Functional and aware of config changes#2samuelcastro merged 9 commits intosamuelcastro:masterfrom
Conversation
…ill prevent error if client is not defined and we try to call getTreatmentsWithConfig. Change lastUpdate to just be 0 instead of null for default value.
samuelcastro
left a comment
There was a problem hiding this comment.
Looks great, just a few small details.
|
Bleh I did a review instead of single comments 🤦♂ |
This removes the need for us to know about every single config option, which would be a pain to maintain.
This allows us to have an onImpression callback property which is idiomatic for React. Also because if the function changed in the config the new function wouldn't be called, because JSON.stringify ignores functions. This is would be confusing for users. Also the fact that we are using JSON.stringify should be transparent, a hidden implementation detail, to users.
|
Ok I'm ready for another review @samuelcastro. I did everything we've talked about so far. I also added custom handling for EDIT: I removed the |
…ether. I think this is slightly more performant (one less render call).
974ff26 to
5ede2df
Compare
|
I thought of another caveat. Since we are memoize the config object before |
|
The changes looks great, I like the idea of freezing the object, this way users will know mutating is a bad idea. Or we could use immer and this mutation would never happen, however once again, I'm avoid unnecessary dependencies. |
…stead they should pass in a new object.
|
I'm going to release it as an alpha version after merge and then after make sure everything is good to go we can make a final release. If you want to test it as well I have a Code Sandbox live where we can easily test it: https://codesandbox.io/s/jovial-banzai-3bc81 |
|
Ok I added the freeze call. I'm now thinking though that we need to tweak again. <SplitProvider config={ core: { authorizationKey: '' } } />This will run the recursive deep freeze and The only solution might be to tell users to memoize their config or define outside of component. |
|
Yeah I don't like idea either, maybe we should leave it as it is and just let users know mutation will produce unexpected results with the client not being re-created. |
|
I liked it more when I didn't think I had to implement recursion myself. I still think we should tell users the best way to write it so we don't have to do |
df4dd25 to
3977119
Compare
3977119 to
a45a85c
Compare
|
Ship it! I'll rebase the other PR next and update docs. |
clientto be nullable.Now we don't have to fake a default client (
{} as SplitIO.Client).This will prevent error if client is not defined and we try to call
getTreatmentsWithConfig.lastUpdateto just be0instead ofnullfor default.Since it is a unix timestamp check 0 functions fine.
lastUpdateto "now" when the client is ready, because I'm pretty sure that's the time it has the treatments loaded from server.By giving all the config options as a dependency list to
useEffect.SplitProviderto a function component.