Super tiny JavaScript MVC framework
- Very Small
- Event emitter (bel.Emitter)
- bel object is aliased in $
- the bel() function is overloaded, is an alias to document.querySelector()
Return a event emitter with special methods
var foo = bel() // or $()
Sets some data to foo
.
var foo = bel()
foo.set({
'a': 23
'b': "baz"
})
Can also be used like this:
var foo = bel().set({
'a': 23,
'b': "baz"
})
Emits a change event.
Returns an item from foo
var foo = bel().set({
"a": {
"b": "Hello World"
}
})
foo.get("a").b //Hello World
This is to make views and controllers
var foo = bel().extend({
...
})
You have to write the logic to keep the models, views, and controllers in sync.
var model = $().set({
"a": 5
})
var view = $().extend({
"el": $("#test"),
"init": function(){
model.on("change", function(){
view.render()
})
},
...
})
var controller = $().extend({
"bel": $("#myButton"),
"iel": $(".myInputElement"),
"init": function(){
bel.addEventListener("click", function(){
model.set({ ... })
})
}
view.init()
controller.init()
No, we don't call init for you. You have to call it.
Returns an event emitter
var a = new bel.Emitter()
a.on("data", function(a){
alert(a)
})
a.emit("data", "Hello World") // -> Hello World
a.off("data", 0) // Removes the callback