Giter Site home page Giter Site logo

Comments (1)

edusperoni avatar edusperoni commented on June 1, 2024

Hey!

Actually, the issue isn't on ngFor but on how loaded works in NativeScript. Loaded emits when the native view is loaded, even if it means it's in the middle of ChangeDetection. This works sometimes in other places because during navigation and bootstrap the views aren't created synchronously as they are when you're using a delayed ngFor.

ngFor does container.createEmbeddedView(template, null) (null being the context) and then manually patches the context, but loaded is happening during createEmbeddedView, so it passes an invalid context to the event.

The new angular integration has just been released (https://blog.nativescript.org/nativescript-angular-12/index.html) and we're wondering on how to best handle this case. Here are the options and pros/cons:

  1. make all events async.
    pros: no more events mid-cd and others
    cons: events are no longer synchronous and can no longer be easily modified. unloaded will never fire as it fires DURING ngOnDestroy (that removes listeners afterwards)

  2. add some kind of event prefix that will fire events async (ngSafe-loaded)='loaded(data)'
    pros: more power to developers
    cons: a bit frustrating to have this issue happen and have to use this as a workaround

  3. treat loaded differently and always fire it async
    pros: same API and everything
    cons: loaded may fire after unloaded! If you create and destroy a component in the same task it may happen. This could get hairy quickly. Other events could also be affected but only loaded is patched

  4. Do nothing. Developers can solve this pretty easily by adding a custom directive like safeLoaded that is an @Output with a setTimeout(emit(),0). We can then add this to the documentation.

It seems there isn't an easy way out of this. On one hand, the event is firing correctly when it should, on the other, it's frustrating to use loaded and have it work differently depending on how it's used. I'm open to suggestions on how to best handle this scenario.

Part of me says we should make clear that loaded and unloaded are not "safe" events, and another part says we should make them behave like the web, which might just be impossible for unloaded.

from nativescript-angular.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.