Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When null is passed as value, it instantiates an empty model in the collection #85

Open
bryanspears opened this issue Aug 11, 2017 · 2 comments

Comments

@bryanspears
Copy link

bryanspears commented Aug 11, 2017

const State = require('ampersand-state');
const Collection = require('ampersand-collection');

const StateCollection = Collection.extend({});

const Country = State.extend({
  collections: {
    states: StateCollection,
  },
});

const ugh = new Country({
  states: null,
});

console.log(ugh.states.length, ugh.states.models.length);

const derp = new Country({
  states: [],
});

console.log(derp.states.length, derp.states.models.length);

Output is 1 1 and then 0 0. Length should be zero in both cases, correct?

@bryanspears
Copy link
Author

Just to be clear, it's not just a length problem. It actually creates an empty model in the collection.

@bryanspears
Copy link
Author

bryanspears commented Aug 11, 2017

Ahhh. It's a problem in ampersand-state: https://github.com/AmpersandJS/ampersand-state/blob/master/ampersand-state.js#L167

Shouldn't ampersand-state let the collection decide what to do with the data? This creates inconsistent behavior between state and collection when used together as desired.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant