GithubHelp home page GithubHelp logo

Comments (6)

ged-odoo avatar ged-odoo commented on August 15, 2024

@alexkuhn could you elaborate?

from owl.

alexkuhn avatar alexkuhn commented on August 15, 2024

Have some crashes because of this, I'm still investigating the issue and will provide short code to reproduce the issue.

from owl.

alexkuhn avatar alexkuhn commented on August 15, 2024

FYI, following LOC makes it crash with observed array item:
https://github.com/odoo/owl/blob/master/src/observer.ts#L28
It happens after the parent is assigned to another object.

from owl.

ged-odoo avatar ged-odoo commented on August 15, 2024

i have a failing test case:

  test("properly handle swapping elements", () => {
    const observer = new Observer();
    const obj: any = { a: { arr: [] }, b: 1 };
    observer.observe(obj);

    // swap a and b
    const b = obj.b;
    obj.b = obj.a;
    obj.a = b;
    expect(observer.rev).toBe(3);

    // push something into array to make sure it works
    obj.b.arr.push("blanche");
    expect(observer.rev).toBe(4);
  });

However, the issue is slightly trickier than I expected. This happens because we unobserve old values when reassigning. It is not hard to make this work for usual situations, but handling cycles in the state is tricky. Not sure yet what to do

from owl.

ged-odoo avatar ged-odoo commented on August 15, 2024

i have a failing test case:

  test("properly handle swapping elements", () => {
    const observer = new Observer();
    const obj: any = { a: { arr: [] }, b: 1 };
    observer.observe(obj);

    // swap a and b
    const b = obj.b;
    obj.b = obj.a;
    obj.a = b;
    expect(observer.rev).toBe(3);

    // push something into array to make sure it works
    obj.b.arr.push("blanche");
    expect(observer.rev).toBe(4);
  });

However, the issue is slightly trickier than I expected. This happens because we unobserve old values when reassigning. It is not hard to make this work for usual situations, but handling cycles in the state is tricky. Not sure yet what to do

from owl.

alexkuhn avatar alexkuhn commented on August 15, 2024

Shorter test that shows the issue:

test("properly handle assigning observed obj containing array", () => {
    const observer = new Observer();
    const obj: any = { a: { arr: [], val: 'test' } };
    observer.observe(obj);

    obj.a = { ...obj.a, val: 'test2' };
    expect(observer.rev).toBe(2);

    // push something into array to make sure it works
    obj.a.arr.push("blanche");
    expect(observer.rev).toBe(3);
  });

from owl.

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.