Giter VIP home page Giter VIP logo

Comments (5)

caridy avatar caridy commented on June 7, 2024 1

After thinking more about this, I think @jbenallen has a good point here. Today, it is impossible for libraries to trigger rehydration, because they don't have a way to produce reactive/tracked objects. More thoughts:

  1. you can get a reactive proxy of any object via track() decorator today (libraries can attempt to do something funky to produce trackable objects (yes, it is a hack, but it is possible).

  2. today, we don't prevent the extraction of a writable version of a read only attribute. they can hack it by assigning the field decorated with @api into a field decorated with @track, and they effectively escape the restriction. We should close this loop asap, and throw an error in this case.

  3. You should be able to get a read only proxy of any object (no exceptions) to protect yourself when sending data like that to non-trusted parties.

  4. I think a method called readonly() makes sense to be part of the library, to match the expectation of @track, and in the future, we can make readonly a decorator, and @track to also function as a regular method to have some symmetry there.

from lwc.

jbenallen avatar jbenallen commented on June 7, 2024

Is the goal here to allow a library (LDS in this case) to emit an object to a wired property that is internally reactive such that one of its properties may be mutated later by the library without replacing the whole thing from the wire and that that internal mutation will be observed by the engine?

from lwc.

davidturissini avatar davidturissini commented on June 7, 2024

My only question about readonly as a decorator, is what happens in this scenario?

import { Element, readonly } from 'engine';

export default class MyComponent extends Element {
  @readonly
  foo = { bar: true }
 
  connectedCallback() {
    this.foo.bar = false; // Error or allowed?
  }
}

It seems we should throw, because that object is readonly, but you also own that object so this restriction may be strange

from lwc.

caridy avatar caridy commented on June 7, 2024

@davidturissini good question. It will throw because it is a readonly. Also, this.foo = {something: 'new'} should also throw, the decorator makes impossible to change that field after initialization.

from lwc.

caridy avatar caridy commented on June 7, 2024

keep in this open until we add the decorator and the docs.

from lwc.

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.