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

Mixin properties get deleted upon being mixed in, making reuse frustrating #110

Closed
mmacaula opened this Issue Nov 26, 2014 · 2 comments

Comments

Projects
None yet
3 participants
@mmacaula
Contributor

mmacaula commented Nov 26, 2014

Consider this code, requirebin example here

var State = require('ampersand-state');

var Selected = {
  session : {
    selected : 'boolean'
  }
}

var Widget = State.extend(Selected,{});
console.log("Selected.session is deleted!! :", Selected); // empty object
var Sproket = State.extend(Selected,{});         

var widget = new Widget({selected : true});

var sproket = new Sproket({selected : true});

console.log('widget is selected: ', widget.selected);   // true
console.log('sproket is selected: ', sproket.selected);  // undefined

I'm guessing the reason State is deleteing the definition is so that you don't have the definitions available as first-class properties on instantiated models. But I'm trying to make reusable mixins and use them across several types of State's and now I'm having to _.clone or wrap them in a function. It would be nice if State did this for me.

I would be happy to submit a PR with tests if you think I'm on the right track.

@lukekarrys

This comment has been minimized.

Show comment
Hide comment
@lukekarrys

lukekarrys Nov 26, 2014

Contributor

@mmacaula Thanks for the issue! I remember hearing about this issue before and found some minor discussion in #68. So I definitely think you're on the right track and we should support objects not being modified when passed to State.extend.

Contributor

lukekarrys commented Nov 26, 2014

@mmacaula Thanks for the issue! I remember hearing about this issue before and found some minor discussion in #68. So I definitely think you're on the right track and we should support objects not being modified when passed to State.extend.

@latentflip

This comment has been minimized.

Show comment
Hide comment
@latentflip

latentflip Nov 26, 2014

Contributor

Fixed in #111, released as 4.4.1

Contributor

latentflip commented Nov 26, 2014

Fixed in #111, released as 4.4.1

@latentflip latentflip closed this Nov 26, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment