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

Add a viewModelView as a view that separates ui and application data #102

Open
pajtai opened this issue Feb 1, 2015 · 2 comments
Open

Comments

@pajtai
Copy link
Member

pajtai commented Feb 1, 2015

This is a view whose this.model is a ui model. It is instantiated from a passed in data model. Methods can be used to sync the two.

@dobbobolina
Copy link

The data model will be an attribute inside this model? What type of methods will this view have that make it different?

@pajtai
Copy link
Member Author

pajtai commented Feb 1, 2015

@dobbobolina below is a rough draft... it's written as an extension of masseuse not a view within it, but aside from that it's pretty much what I have in mind:

define(['masseuse'], function(masseuse) {
    'use strict';

    var RivetsView = masseuse.plugins.rivets.RivetsView;

    return RivetsView.extend({
        initialize : initialize,
        saveViewModel : saveViewModel,
        loadViewModel : loadViewModel
    });

    function initialize(options) {
        if (options.model) {
            this.dataModel = options.model;
            options.model = this.dataModel.clone();
        }

        RivetsView.prototype.initialize.call(this, options);
    }

    function saveViewModel() {
        if (this.beforeSaveViewModel) {
            this.beforeSaveViewModel();
        }

        this.dataModel.set(this.model.attributes);

        if (this.afterSaveViewModel) {
            this.afterSaveViewModel();
        }
    }

    function loadViewModel() {
        this.model.set(this.dataModel.attributes);
    }
});

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