mvstar
MV★ framework. No fancy virtual DOM. Minimal bits needed for sensible client-side applications. Declarative one-way databinding. Event emitters. Simple routing. Computed properties. Completely explicit. No dependencies outside of a dollar library.
Views
Views encapsulate bits of DOM. Generally like Backbone views but with declarative one-way databinding.
# Can reference a template tag in the DOM, which will be used to create new # view instances template: '#line-item-template' # Or alternately bind to existing element: # el: '#line-item' # Declare bindings from state -> selectors in DOM. You can use @ to target # specific attrs. bindings: img: 'img.thumbnail @src' sku: 'input.sku @value' name: 'a.title' # Computed properties, generated from different bits of state. computed: : colorsize # Watch for changes, and recompute on changes. watching: desc: 'color''size' # Format state before rendering into DOM. formatters: : if vlength > 1 vjoin ' / ' else vjoin '' # Bind to events. events: 'change .quantity input': 'updateQuantity' 'click .remove-item': 'removeItem' # You need to manually unbind events if you define any. : -> @unbind @remove # Handle change event : # Get quantity, el refers to current target of event quantity = parseInt $elval10 # Update quantity on state bound to this view @set 'quantity'quantity false
Events
Extend from mvstar.EventEmitter
and wire up things with events.
: super @cart ?= @subtotal = 0 @quantity = 0 : @cartsku # You must manually emit things you care about. : @emit 'add'item @quantity += itemquantity @subtotal += itemquantity * itemprice if @get itemsku? @cartitemskuquantity += itemquantity else @cartitemsku= item @ : @emit 'remove'@cartsku delete @cartsku @ : -> @emit 'clear' @cart = @