NathanWalker / ShoutOutPlay

The mobile app that allows you to create and record personal dedications using your favorite music playlists for corporate events, parties, weddings and get togethers.
https://shoutoutplay.com
30 stars 7 forks source link

FIX: Angular change-detection is not triggered on login #11

Closed vakrilov closed 8 years ago

vakrilov commented 8 years ago

Fixes the problem when the search screen is not updated after login.

Problem

Callbacks for the Spotify plugin are not executed inside the zone so the change detection is not triggered on login.

Local Solution

Wrap all callbacks in a ngZone.run()

Plugin Solution

There is zonedCallback method in the NativeScript modules that we use to wrap native callbacks (for example setTimeout() ). It will automatically execute the callback in the current zone (if there is a global Zone object). You can use that in the Spotify plugin to wrap all the event callbacks.

NativeScript Core Solution

Consider wrapping all Observable.notify() calls in zonedCallback. This might have performance implications though. I will open an issue for discussion in NativeScript repo

vakrilov commented 8 years ago

Issue opened in NativeScript repo: NativeScript/NativeScript#2229

NathanWalker commented 8 years ago

Brilliant. Of course this makes sense! Thank you Alex. I'll merge this as it will fix this. Wrapping observable.notify is an interesting proposal there. This case I would consider user error as I should have known those callbacks needed to be in a zone callback and that sort of thing should be in the tips/tricks section of nativescript.org/angular as well as mentioned throughout the {N}+ng2 guide; I'll look into adding a section about that.