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

Have scheme work for collections of items #75

Open
tommoor opened this issue Mar 23, 2015 · 2 comments
Open

Have scheme work for collections of items #75

tommoor opened this issue Mar 23, 2015 · 2 comments

Comments

@tommoor
Copy link
Contributor

tommoor commented Mar 23, 2015

It would be nice if the scheme validation and calculation methods also worked for a collection of items as this is typically how Flux stores are arranged. If we discuss some syntax I can probably take this on... my thinking is another attribute on the stores isCollection: true for example.

@darcyadams
Copy link
Collaborator

agreed. This bugs me as well. I find myself operating directly on scheme properties, usually when dealing with arrays.

Not sure I follow exactly what you are proposing. Other frameworks, such as Backbone, have solved this by mixing in a library like underscore, and I'm not sure I want to introduce a dep like that. Can you be more specific about how you envision this working?

@tommoor
Copy link
Contributor Author

tommoor commented Mar 24, 2015

From an API point of view, i might suggest something like this:

Store is a single 'model' (same as now):

var Artist = Flux.createStore({
  scheme: {
    firstName: {
      default: 'Unknown'
    },
    lastName: {
      default: 'Artist'
    }
  }
});

Store is a collection of 'models':

var Artists = Flux.createStore({
  collection: true,
  scheme: {
    firstName: {
      default: 'Unknown'
    },
    lastName: {
      default: 'Artist'
    }
  }
});

In my own stores of this nature I also have the methods add, remove and update that could work something like:

Artists.add({
  id: 1,
  firstName: 'Elvis',
  lastName: 'Presley'
});

Artists.update({id: 1}, {
  firstName: 'Lisa'
});

Artists.remove({id: 1});

Calling set on this store would throw an error.

Maybe this is overkill? Honestly I'm not sure if this is the direction that you want to take delorean or not, it's definitely moving into the backboney arena but that might be a good a thing as I think there will be a lot of folks moving over and hoping for a little more sugar.

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

2 participants