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

Extending to support buffered mode? #6

Open
alexander-alvarez opened this issue Feb 24, 2017 · 5 comments
Open

Extending to support buffered mode? #6

alexander-alvarez opened this issue Feb 24, 2017 · 5 comments

Comments

@alexander-alvarez
Copy link

alexander-alvarez commented Feb 24, 2017

Would you be open to having a buffered mode? / how hard would it be to leverage the same tracking mechanism you have but in addition to:

    let info = {foo: 1};
    let projects = makeList('project', 2);
    let [project1] = projects;
    let pets = makeList('cat', 4);
    let [cat, cat2] = pets;
    let bigCompany = make('big-company');
    let smallCompany = make('small-company');

    let user = make('user', { profile: profile1, company: bigCompany, pets, projects });

   // manual tracking model means you have to explicitly call => startTrack
    // to save the current state of things before you edit
    user.startTrack();   

    // edit things  
    user.setProperties({
      'info.foo': 3,
      company: smallCompany,
      profile: profile2,
      projects: [project1],
      pets: [cat1, cat2]
    });

    user.rollback();

    // it's all back to the way it was
    user.get('info') //=> {foo: 1}
    user.get('profile') //=> profile1
    user.get('company') //=> bigCompany
    user.get('projects') //=> first 2 projects
    user.get('pets') //=> back to the same 4 pets

we could also do:

   // manual tracking model means you have to explicitly call => startTrack
    // to save the current state of things before you edit
    user.startTrack({buffered: true});   

    // edit things  
    user.setProperties({
      'info.foo': 3,
      company: smallCompany,
      profile: profile2,
      projects: [project1],
      pets: [cat1, cat2]
    });

    // nothing has changed
    user.get('info') //=> {foo: 1}
    user.get('profile') //=> profile1
    user.get('company') //=> bigCompany
    user.get('projects') //=> first 2 projects
    user.get('pets') //=> back to the same 4 pets

    user.applyChanges();

     // changes are applied
    user.get('info') //=> {foo: 3}
    user.get('profile') //=> smallCompany
    user.get('company') //=> profile2
    user.get('projects') //=> [project 1]
    user.get('pets') //=>  [cat1, cat2]

a la
https://github.com/yapplabs/ember-buffered-proxy

@danielspaniel
Copy link
Owner

danielspaniel commented Feb 24, 2017

Now that is an interesting idea .. I must say. Don't think it would be hard, just take a few days because it requires alot of new tests. You want to try for a PR, or you want me to try it?

How does the buffered apply to auto tracking? Maybe there could be another option to buffer when tracking.

Also there is an open issue in that buffered-proxy for handing belongsTo and hasMany .. so this would actually not work unless I could figure out how to make that work.

@alexander-alvarez
Copy link
Author

I could take a stab at it if you're not opposed to the API, it will likely take me a bit longer though

How does the buffered apply to auto tracking? Maybe there could be another option to buffer when tracking.

you could probably configure it as you do auto.

Also there is an open issue in that buffered-proxy for handing belongsTo and hasMany .. so this would actually not work unless I could figure out how to make that work

I'm not sure what you're referring to here

@danielspaniel
Copy link
Owner

danielspaniel commented Feb 24, 2017

yapplabs/ember-buffered-proxy#7

Let me give this a try and I will probably find out the issue they are dealing with.

Also, you could just use buffered proxy for change tracking too right?

It is almost as if that concept eliminates the need for change tracker on the ember-data model, since your doing it on a proxy.

@alexander-alvarez
Copy link
Author

I was perusing that earlier, not sure I see any blockers to what we need to do.
I'll share any progress I make as I make it.

@danielspaniel
Copy link
Owner

danielspaniel commented Feb 24, 2017

But I am asking you .. could you use the buffered proxy right now to do change tracking and rollback on an ember-data model?
I am guessing you can not since it does not handle relationships?

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

No branches or pull requests

2 participants