Comments (3)
Is this bug or I do something wrong?
It's the feature. When carLink.at('manufacturer')
is updated, it assumes that carLink is the plain object or array because it needs to know how to properly clone it. That's how nested link update is done: it creates the copies of the parent chain so that setState or other state management libraries could detect that direct state member is changed using the shallow comparison.
Therefore, no classes as state members are supported. As this is not the way to go in a large application, we're at Verizon/Volicon are not using NestedLink alone, but as a part of NestedReact. Which replaces React's state with observable and serializable classes. https://github.com/Volicon/NestedReact
Here is an example. In order to get ES6 classes syntax you need to use "rc" version. It will be released soon.
https://github.com/Volicon/NestedReact/tree/develop/examples/checklistTree
from nestedlink.
As an alternative, it is possible to create the fork of NestedLink to support immutable classes.
The easiest way to go is to add your own "helper". Put it in the third option to the switch (note that built-ins like Date should still go through the dummyHelper). Here:
https://github.com/Volicon/NestedLink/blob/master/valuelink.ts#L298
Helper is a combination of clone
, map
, and remove
functions. That's what NestedLink must know how to do for your classes in order to operate properly. clone
is essential. Others are needed only if you want to use corresponding operations in your classes.
I would just forward these operations to the object in your helper, and created the base class with such an operation. Generic "clone" operation can be implemented in the base class like this:
clone(){
const copy = new this.constructor();
Object.assign( copy, this );
return copy;
}
In simple cases, it should work just fine.
from nestedlink.
ok. Thank you.
from nestedlink.
Related Issues (20)
- link.props must work with checkbox and radio
- input element loses focus after typing HOT 9
- Bug: eMail input auto trims value and resets cursor position HOT 1
- Working on a nestedlink course/docs for class HOT 1
- Add custom validation pattern to the docs HOT 2
- Enhancement: Convenience onX method binding pattern for Link.Component classes HOT 1
- LinkeComponent.links is null HOT 1
- IE9: deleting data in input doesn't go to the state HOT 1
- TypeError: Cannot read property 'value' of undefined at Input (tags.js:64) HOT 1
- Documentation about type="radio" HOT 2
- Validation don't reevaluates when a dependent state changes HOT 1
- Could not find a declaration file for module 'valuelink/tags'
- Is there a way to handle `undefined` values?
- Question: how to link a property which is an array of objects HOT 1
- valuelink cannot be used server side HOT 2
- onChange is called before state is changed
- LinkAll with React.useState hook HOT 2
- Synthetic event error when using useLink with value inicialization.
- Input type "number" in NumberInput in linked-controls
- Module not found: Can't resolve 'tslib'
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 nestedlink.