Skip to content

declarative syntax for wrapping important selectors behind functions

Notifications You must be signed in to change notification settings

mbriggs/backbone-view-fields

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

View Fields

Working with backbone on some non trivial projects, I found that views should really encapsulate important bits behind functions, to isolate the rest of the view code from changes to selectors (i.e. a change to the html means a change to the view code in a single place).

I really like the declarative syntax for view events, and wanted similar for what are essentially view fields.

Examples

Foo = Backbone.View.extend({
  fields: {
    header: '.header',
    addButton: '.header button:first',
  },

  initialize: function() {
    ViewFields.init(this)
  }
})

var view = Foo.new()

view.fields.header() // returns view.$('.header')
view.fields.addButton() // returns view.$('.header button:first')

view.fields.add({new: 'span.new'})
view.fields.new() // returns view.$('span.new')

About

declarative syntax for wrapping important selectors behind functions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published