Closed sackIndian closed 11 years ago
This looks as though it is getting very complicated! For a start, things are going to get messy if you are nesting models inside models.
I need to know what the problem you are trying to solve is before I can suggest a better way. FruitMachine is a collection of relatively low level tools, so it is up to you how you use them.
In the future if you syntax highlight and properly indent your code inside GitHub issues, people will be able to read it more easily. I've done it for you in the post above.
I want to eliminate the json object, if it repeats in several child slots with single object?
You don't have to create modules using the JSON technique, you can instantiate modules as you need them, and assemble your view manually:
var Apple = fm.define({
name: 'apple',
template: appleTemplate
}):
var Orange = fm.define({
name: 'orange',
template: orangeTemplate
}):
// Use them
var apple = new Apple();
var orange = new Orange();
// Add orange as a child of apple
apple.add(orange);
If you wanted the share a model across several modules.
var Model = fruitmachine.Model;
var model = new Model({ foo: 'bar' });
var layout = {
module: 'layout-a',
children: {
1: {
module: 'apple',
children: [
{
module: 'masthead',
model: model
},
{
module: 'masthead',
model: model
}
]
},
2: {
module: 'banana',
children: [
{
module: 'masthead',
model: model
},
{
module: 'masthead',
model: model
}
]
}
}
};
If you want to share data, but have custom stuff in other modules, just store a reference to shared stuff inside the module's model.
var Model = fruitmachine.Model;
var model = new Model({ foo: 'bar' });
var json = model.toJSON();
var layout = {
module: 'layout-a',
children: {
1: {
module: 'banana',
children: [
{
module: 'masthead',
model: {
shared: json,
unique: 'stuff'
},
{
module: 'masthead',
model: {
shared: json,
unique: 'thing'
}
}
]
}
}
};
Not that clean, but it can be done. Most components in applications are a visual representation of a single model. Imagine a dashboard of widget, one might be showing you the weather, one might be showing you the news, each widget would have a very different model.
I hope this helps you out somewhat :)
Thanks @wilsonpage.
It is little bit tough process, in following layout structure it made me to create several models before creating a view and is difficult to achieve.