Comments (5)
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:
-
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). -
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. -
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.
-
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 makereadonly
a decorator, and@track
to also function as a regular method to have some symmetry there.
from lwc.
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.
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.
@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.
keep in this open until we add the decorator and the docs.
from lwc.
Related Issues (20)
- Fix `className` types in `engine-core`
- Audit and consolidate usage of `null` and `undefined` in the engine HOT 1
- Investigate invalid types generated in `@lwc/shared/language.ts` HOT 1
- Adding multiple animations to an element breaks compiler's keyframe name replacement. HOT 2
- [HMR] `swapStyle()` API should swap CSS content rather than appending it HOT 3
- LWC compiler errors on `.jsx`/`.tsx` files HOT 6
- Normalize whitespace for `style` and `class` attributes (breaking change) HOT 2
- Inline styles do not parse `! important` correctly due to extra whitespace HOT 15
- Bundle our licenses correctly in our npm packages
- lwr project does not run anymore (sudden death) HOT 1
- Use `node:` protocol for all builtin imports (`fs`, `path`, etc.) HOT 1
- Specify the minimum supported version of Node in `engines` HOT 1
- Reduce verbosity in `template.stylesheets` generated code
- Switch from Jest to Vitest HOT 1
- [HMR] `swap*` APIs show stale content when swapping back and forth multiple times HOT 1
- [HMR] `swapStyle()` API does not account for stylesheet collisions
- [HMR] `swapStyle()` does not work for `static stylesheets`
- Executing Static Resources within LWC HOT 1
- Inconsistent attribute ordering between static/dynamic nodes
- Lightning-datatable has wrong type of parameters passed to custom type columns through typeAttributes that passsed not with "fieldName" HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lwc.