Comments (4)
Hello, @loweoj,
yeah, I didn't notice that when it was developed. The problem happens because when you try to set a value for the attribute inside the constructor, this will still be undefined: https://github.com/talyssonoc/structure/blob/master/src/attributes/descriptors.js#L25
A solution I can think for that is to always check if this[ATTRIBUTES]
exists and, if no, set a value for that inside the getter. I'm not sure about the performance of that conditional tho (shouldn't be a problem). What do you think?
from structure.
You mean modify the setter for an attribute?
We just need instance[ATTRIBUTES] = Object.create(null);
to be called before the instance constructor, or before attempting to set an attribute.
from structure.
That's the problem, we don't have an instance to assign it before the instance constructor. I mean modifying the getter of instance.attributes
(which delegates to instance[ATTRIBUTES]
) so it'll be always present.
from structure.
Hello, @loweoj! I've been working on Structure v2 (it's already in alpha in case ou wanna test) and I was thinking about a solution for that in v2. Would your proposed solution in #100 work for attributes with dynamic defaults, mainly if these dynamic defaults access instance methods?
from structure.
Related Issues (20)
- Nested dynamics types isn't work HOT 2
- Getters / attributes not serialized HOT 2
- Apply other validations over arrays
- problem with new js debugger vscode HOT 1
- Question: How to validate object keys?
- Schema subclass loses validate method HOT 2
- [Feature Proposal] Allow users to extend default options HOT 3
- Get other attribute value from a function called within a default value HOT 3
- Improve .eslintrc
- Add complexity checking to ESLint
- Custom validation message HOT 1
- Empty String Converted to 0 and returns Valid HOT 2
- Support Map types with itemType HOT 3
- validation for specific attribute
- custom validation HOT 1
- option to override property on validation HOT 4
- Dynamics Defaults Values aren't working HOT 1
- Allow custom toJSON method on class for serialization. HOT 4
- Method to clone an existing structure. HOT 1
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 structure.