Giter VIP home page Giter VIP logo

Comments (4)

berickson1 avatar berickson1 commented on May 17, 2024 1

@dabit3 In our usage or ReSub, we've actually defined a ReadOnlyArray type that we often return from stores to prevent exactly these classes of issues.

interface ReadOnlyArray<T> {
    readonly [n: number]: T;
    readonly length: number;
    concat(...items: (T | T[])[]): ReadOnlyArray<T>;
}

from resub.

berickson1 avatar berickson1 commented on May 17, 2024

@dabit3 I believe you've actually found a bug in the example :(
Data returned from stores should be immutable (using typescript readonly is a good way to do that for the objects, but arrays can be tricky). If you mutate an object in a store, you end up changing the value in the component since it wasn't deep cloned before returning (for perf reasons)

instead of:

    addTodo(todo: String) {
        this._todos.push(todo);
        this.trigger();
        console.log('t_todos:', this._todos)
    }

do

    addTodo(todo: String) {
        this._todos = this._todos.concat(todo);
        this.trigger();
        console.log('t_todos:', this._todos)
    }

I'll update the example

from resub.

dabit3 avatar dabit3 commented on May 17, 2024

Awesome, that worked! Thanks for your help.

from resub.

dabit3 avatar dabit3 commented on May 17, 2024

@berickson1 Ah nice, thanks for this!

from resub.

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.