Skip to content
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

Changes made while observers are paused are still reported when observers are resumed #65

Open
hybridwebdev opened this issue May 4, 2024 · 2 comments

Comments

@hybridwebdev
Copy link

hybridwebdev commented May 4, 2024

As the title describes, when you pause observers attached to an observable proxy, changes are still tracked. When the observer is resumed, any changes made while paused are also reported.

let state = {
foo: "bar"
}

let observable = observableSlim.create( state, 100, changes => console.log(changes) )

ObservableSlim.pause( observable )

state.foo = "baz"

ObservableSlim.resume( observable )

state.snah = 'bo'

the result will log both changes, despite one being made while the observer is paused.

I don't know if this is intended behavior or not, but to me it definitely feels like an oversight. This little issue cost me the better part of 2 weeks of headaches.

My solution was just to add

changes.push({
   ...other properties given in the push statement,
    observablePaused: observable.paused
});

to both places that you do changes.push() and then filter the results in my observer function. I took this approach as the change seems 100% non-breaking to the existing code base.

@Kingnaoufal
Copy link

Hi,

I think both behaviors are wanted. If we want to emulate manual batching of changes, first, we pause the changes and resume to consume all of them in one batch.
Another case is to discard the changes if the change capture is paused.

Maybe having and explicit API to describe the wanted behavior should be fine

Thanks

@hybridwebdev
Copy link
Author

Hi,

I think both behaviors are wanted. If we want to emulate manual batching of changes, first, we pause the changes and resume to consume all of them in one batch. Another case is to discard the changes if the change capture is paused.

Maybe having and explicit API to describe the wanted behavior should be fine

Thanks

Thanks for replying. I think the cleanest approach is to just flag changes as they occur with the flag I indicated in my example. It's a very small change but gives more control without complicating the API or having to worry about breaking changes. Then developers can just use the flag as part of their callback when the updates occur.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants