Could we make Fruit Machine not a Singleton?
Closed this issue · 4 comments
matthew-andrews commented
Further to our discussion it would be great if Fruit Machine were not a singleton.
- Perhaps we could have a default build of Fruit Machine (the simple case) which was a singleton - it just creates the Fruit Machine, sets it up, pulls in the default model, etc.
- Then for more advanced cases you could bring your own model, potentially instantiate more than one Fruit Machine within a single page.
Perhaps the core of Fruit Machine could move into a separate repo (fruitmachine-core) in the same way as buster.js?
This library is going to be so perfect it'll never actually get shipped...
matthew-andrews commented
Actually this looks pretty easy. The way you've done helpers now (very nice btw) is just passing them via reference. The only thing that needs to change is lib/store.js
needs to be able to be instantiated inside lib/index.js
and then have its object passed around... I might even be able to do this 😮.
var FruitMachine = require('fruitmachine');
var myFM = new FruitMachine();
myFM.define({
module: 'hackberry',
template: function(){ return 'I am an apple' }
});
myFM.define({
module: 'layout',
template: function(data){ return data.child1 }
});
var View = myFM.View;
var layout = new View({
module: 'layout', /* 1 */
children: [
{
module: 'hackberry', /* 1 */
id: 'child1'
}
]
});
layout
.render()
.inject(document.body);
matthew-andrews commented
Going to have a go at this. Wish me luck.
wilsonpage commented
var fm = new FruitMachine({
model: Backbone.Model,
// ... other config
});
fm.define({
module: 'apple',
template: function(){ return 'I am an apple' }
});
fm.modules.Apple //=> Apple
matthew-andrews commented
I think it's safe to say this is pretty much done now and will land in V0.4.x.