Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Model inheritance and parseModel functionality

$
0
0
Hello,

I'm working on my current project and got confused by how parseModel actually works.
I have a base model like abstract QuestionModel that extends can.Model and provides customized REST methods and parseModel. It also contains basic functionality and common question attributes.

Then I want to add concrete models for each question type I have. So I basically have the following:

var QuestionModel = can.Model. extend({

      create: function(...) {..},

parseModel: function(...) {...}

}, {});

var ConcreteQuestion = QuestionModel.extend({...}, {...});

The problem here is that parseModel doesn't work for ConcreteQuestion. Moreover if I move parseModel to ConcreteQuestion the method is invoked twice. And if I have some logic in that method the second call breaks the logic (because incoming data differs from data in first method call)

After examining the code I assume that the behavior is caused by ajaxMethod initialization logic. Basically QuestionModel is setup first creating all methods like makeCreate/create etc. And then ConcreteQuestion is initialized invoking the same logic but using those already created methods.

So the question is:

Is it possible to inherit from base model and not break REST functionality?
A good idea would be probably to use mixins here but there is no support for mixins in the framework.

Any ideas how to share common functionality in models are greatly appreciated.

Thank you.






Viewing all articles
Browse latest Browse all 3491

Trending Articles