UNPKG

2.16 kBJavaScriptView Raw
1'use strict'
2
3var Base = require('ribcage-view')
4 , _ = require('lodash')
5 , State = require('ampersand-state').extend({
6 // forces you define all properties on the state model
7 // this helps catch bugs and makes code more readable
8 extraProperties: 'reject'
9 // output the derived properties and the props in toJSON
10 , toJSON: function toJSON(){
11 return _.extend(this.serialize(), this.getAttributes({derived: true}))
12 }
13 })
14 , {{PascalName}}Step
15
16{{PascalName}}Step = Base.extend({
17
18 template: require('./template.html.hbs')
19
20, className: '{{camelName}}Step'
21
22, State: State.extend({
23 props: {
24
25 }
26 })
27
28// Backbone Events
29, bindEvents: function bindEvents(){
30 // always stopListening so we don't reattach multiple listeners
31 if (this.state){
32 this.stopListening(this.state)
33 // listen to state, model, etc… events
34 // this.listenTo(this.state, 'change:text', this.onStateChangeText)
35 }
36 }
37
38// e.g.
39// , onStateChangeText: function onStateChangeText(state, value){
40// console.log(value)
41// }
42
43// helper methods
44// e.g.
45// , findModelIndex: function findModelIndex(model){
46// this.collection.findIndex(model)
47// }
48
49// public methods
50// e.g.
51// , getLabel: function getLabel(){
52// return this.state.label
53// }
54//
55// , setLabel: function setLabel(label){
56// this.state.label = label
57// }
58
59// Create Subviews
60// , createSubviewName: function createSubviewName(){
61// return new SubviewName({})
62// }
63
64// Lifecycle Methods
65, beforeInit: function beforeInit(options){
66 // check for required props
67 var requiredProps = this.State.prototype._definition
68
69 _.each(requiredProps, function eachRequiredProp(setting, prop){
70 if (setting.required && _.isUndefined(options[prop]))
71 throw new Error(this.className + ' requires ' + prop)
72 }, this)
73
74 this.state = new this.State(options)
75 }
76
77, afterInit: function afterInit(){
78 // this.subviewName = this.createSubviewName()
79 }
80
81// , beforeRender: function beforeRender(){
82// }
83
84, afterRender: function afterRender(){
85 // this.appendSubview(this.SubviewName)
86 }
87
88})
89
90module.exports = {{PascalName}}Step