Comments (8)
The old way of for (attr in attrs)
would not throw on null or undefined.
from ampersand-state.
This was changed in an optimizaton PR from @STRML c6a16ed
Looks like an edge case not currently covered in tests got broken.
from ampersand-state.
So I think I've managed to track down what conditions cause null
to be passed as the key
argument to set
.
Say I have a model that contains another model as child property:
var User = State.extend({});
var Post = State.extend({
children: {
user: User
}
});
Then I fetch some data from the server where user
is null
(intentionally)
{
"user": null
}
Then it comes time to set the Post's user property with null
//L165
this[attr].set(newVal, options);//attr = "user", newVal = `null`
which is where things break.
This should demonstrate that null
is a valid value to be passed to set
when setting a child model. (or at least it had been working previously).
A quick fix might be to change Object.keys(attrs)
to Object.keys(attrs || {})
on L155. This also demands another test case. I'm happy to submit a PR with the above fix and a test case for null
from ampersand-state.
Gotcha - I'll add a failing test for this and fixup set()
.
from ampersand-state.
Ah @dhritzkiv if you're willing to do a PR that'd be great - pretty busy here today - I appreciate it.
from ampersand-state.
Yep. Can do.
from ampersand-state.
Heads up there's a PR for this now from another contributor. Looking into why the travis tests are failing.
from ampersand-state.
fixed in v4.9.1
from ampersand-state.
Related Issues (20)
- state.collections referecing itself HOT 6
- Possible need for semver major HOT 1
- I should be able to modify State's getters and setters for an individual attribute HOT 4
- Upgrade lodash dependency to 4.* HOT 15
- document that isValid can be passed Object
- overriding functions fails since 5.0.0 HOT 3
- Don't recalculate derived properties until next access HOT 4
- `initialize` is sometimes called before initial attributes have been set HOT 2
- Derived properties are calculated unnecessarily often HOT 1
- Decrease module(s) size HOT 2
- New lead maintainer required HOT 6
- use lodash modules, not full HOT 1
- Derived properties and on change listener sequence
- es6 class compatibility HOT 3
- Is there an equivilent to hasOwnProperty for ampersand models? HOT 2
- collections and child properties not working when packed by react native HOT 4
- State always creates empty model in child collection. Inconsistent behavior
- `change:a.x` fired, while no `change:a` firing? HOT 2
- def.values.join is not a function 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 ampersand-state.