Giter Site home page Giter Site logo

Comments (8)

mmun avatar mmun commented on July 19, 2024 2

We'll be exploring some solutions to this issue soon.

That said, I'm actually excited to see how far we can get with shallow tracking. In ember, there is a cost to supporting things like @each. There's a large performance cost associated with managing all the observers it installs. There's also a burden on the developer to use Ember's array APIs when interacting with the array.

from glimmer-component.

MartinMalinda avatar MartinMalinda commented on July 19, 2024 1

This is also needed for tracking the change of args. Though maybe there will be a workaround later when didUpdate hook is introduced.

from glimmer-component.

mmun avatar mmun commented on July 19, 2024 1

@michalsnik The solution is to use the data down, actions up programming model. Instead of trying to mutate the state of the todo in the todo-item directly, you should pass a callback in that mutates the todos from the root.

I've been working on implementing the todomvc app in glimmer but I need to fix this bug first: #34

from glimmer-component.

michalsnik avatar michalsnik commented on July 19, 2024

Thanks for a quick answer. I'm aware of the extra cost of this, but I'm not seeing other possible solutions to this problem. Also I found that if I pass object to a component, for example:

<todo-item @todo={{todo}} />

Then if I change one property of the given todo in parent component - the child component does not re-render. Is there any workaround to make it work?

from glimmer-component.

michalsnik avatar michalsnik commented on July 19, 2024

@mmun I know DDAU and I never wanted to mutate todo in todo-item. The problem is even if I mutate single todo in todos' parent component - the child component (todo-item) won't re-render. Maybe if I'd pass name and state separately instead of the full object it would work, but that's something I'd like to avoid. I'd be happy to see how you proceed with todomvc :)

from glimmer-component.

mmun avatar mmun commented on July 19, 2024

@michalsnik: Here's my first pass: https://github.com/glimmerjs/todomvc-demo.

The main data flow is set up, but there are still a few issues I'm going to leave for contributors.

from glimmer-component.

hoodwink73 avatar hoodwink73 commented on July 19, 2024

Coming from React world, it is very intuitive for me to think that whenever an argument to a child changes the component will re-render. But I think GlimmerJS chooses to re-validate the component tree whenever a tracked property is changed.

The current todo-mvc implementation chooses to create a todo store with title and completed as tracked properties.

import { tracked } from "@glimmer/component";

let _idSequence = 0;

export default class Todo {
  private _id: number = _idSequence++;

  @tracked title: string;
  @tracked completed: boolean;

  constructor(title: string, completed: boolean = false) {
    this.title = title;
    this.completed = completed;
  }

  toggle() {
    this.completed = !this.completed;
  }
}

So, a change to them should trigger a re-render. A new thing I noted here, one can have tracked annotation outside the component.

My understanding is still a bit blurry but I wanted to share it either way. I think the circumstances under which a glimmer app re-renders is a crucial piece to understand.

from glimmer-component.

rwjblue avatar rwjblue commented on July 19, 2024

This repo has been merged with glimmerjs/glimmer.js (into a monorepo setup). I am not sure if this issue is still applicable, but if you could confirm it is still an ongoing concern and open it over there that would be very helpful.

Sorry for the noise, but thank you for your help!

from glimmer-component.

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.