mirror of
https://github.com/appy-one/acebase.git
synced 2026-05-25 06:02:14 -06:00
[GH-ISSUE #25] Docs for proxy.onMutation((mutationSnapshot, isRemoteChange) and possible issue. #26
Labels
No labels
IndexedDB
browser
bug
dependencies
documentation
duplicate
enhancement
feature request
indexes
indexes
invalid
pull-request
query
question
transaction logging
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/acebase#26
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @clibu on GitHub (Mar 22, 2021).
Original GitHub issue: https://github.com/appy-one/acebase/issues/25
Originally assigned to: @appy-one on GitHub.
I was running into an endless recursion issue with an
onMutation()callback. I finally worked out that I needed to skip my code in the callback whenisRemoteChangeis true.ie. The
onMutation()callback was called twice for a single mutation change. Once withisRemoteChangefalseand again with ittrue.I can't find any info on
isRemoteChangeother than the example code???A bit more detail. I'd set
someProxy.stop = truewhen it wasfalse. Then I'm setting it to true again whichdata-proxy.tscode ignores, because the value hasn't changed. I'm simply adding this info in case it is relevant.@appy-one commented on GitHub (Mar 23, 2021):
The
isRemoteChangeparameter tells you whether the change was made through the proxy itself (isRemoteChange === false), or outside the proxy (isRemoteChange === true), eg through aref.update(...). If you change something in your mutation callback, you'll get another callback because there's another change.I'll add this to the documentation. You might want to check out the related
onChangedhandler on your proxied objects, the jsdoc has this info:By the way
proxy.stopis a function you would call to destroy the live data proxy, I'm assuming you're referring to a stored value in the proxied object? As inobj.stop = true?@clibu commented on GitHub (Mar 23, 2021):
Ok, thanks for the extra info. I don't think I'm doing a
ref.update()on this property but will check.The proxy value is being updated in two different places though. The second assignment has the current value, so no change is being done. Could this be causing the 2nd
onMutation()callback call withisRemoteChangetrue.Yeah
stopproperty name was picked at random. I do useproxy.destroy()which is what you meant here.@clibu commented on GitHub (Mar 23, 2021):
I've had more of a look into why I'm getting a second mutation callback with
isRemoteChange = true. I'm definitely not doing anyref.update()and am only doing an assignment to the proxy once.The second call is coming via storage.js
trigger()on line 484 doing ' Subscribe to mutations events on the target path' on line 114 in data-proxy.tsI don't have any mutation subscriptions that I'm aware off. Further this seems Browser db related as a simple test in Node.js doesn't exhibit the issue.
Maybe it is supposed to behave this way, in which case it needs to documented along with it behaving differently depending on the storage method?
@appy-one commented on GitHub (Mar 23, 2021):
The quickest way for me to investigate this is if you can you provide sample code I can test with in the browser
@clibu commented on GitHub (Mar 24, 2021):
Leave it with me. Won't be until later in the week.
@appy-one commented on GitHub (Mar 24, 2021):
I've updated the jsdoc description for
onMutation, published withacebase-corev1.2.6@clibu commented on GitHub (Mar 25, 2021):
OK, I've tracked down why I'm seeing
isRemoteChange = trueand two calls to myOnMutationcallback and it is most likely my problem.I have two proxies, one on a parent and one on a child path with the same callback function used for both.
When I change a value in the child path it's proxy
OnMutationcallback sees it withisRemoteChange = falseand the parent proxyOnMutationcallback sees it withisRemoteChange = true.Because I'm using the same callback function for both proxies I didn't realize the two calls were for separate proxies.
Here's a sample that shows the issue, but with two
OnMutationhandlers.So is this the behaviour you expect?
And am I wrong using two proxies on the same path?
@appy-one commented on GitHub (Mar 25, 2021):
Yes, this is expected behaviour. You change the
showBarproperty through proxy2, so in its callbackisRemoteChange === false. proxy1 is notified of a change made outside of its knowledge so it fires its callback withisRemoteChange === true.Why would you want to use 2 proxies on the same path though? The idea behind a proxy is that you can use them as normal objects ("state") and share it throughout your app so you don't have to worry about database updating and synchronization anymore. Instantiate a proxy somewhere in your code once, use it everywhere as if its just local state.