3 category: JavaScript libraries
13 Spine is an MVC framework for JavaScript.
15 - <https://spine.github.io/>
19 class User extends Spine.Model
20 @configure "User", "name", "address"
23 [@first, @last].join ' '
28 User = Spine.Model.sub()
32 .configure 'modelname', attributes...
43 .on 'refresh change', (user) -> ...
46 .change (user) -> ... # same as on('change')
47 .fetch (user) -> ... # same as on('fetch')
50 .toJSON() # all records
51 .fromJSON(json) # from json string
55 .records # Hash of instances
56 .attributes # array of attributes (from .configure)
59 .toString() #=> "User"
63 .find(1) # throws error
66 .select (u) u.name == 'bob'
67 .findByAttribute 'name', 'bob'
68 .findAllByAttribute 'name', 'bob'
71 .slice(6, 13) # cloned copies of instances
83 .destroyAll({ ..options.. })
96 .validate() # validate = (-> "Name required" unless @name)
98 .attributes() # hash of attr values
99 .eql(other) # equality check
105 .updateAttribute("name", "john")
106 .updateAttributes(name: "John")
119 .dup() # clone as unsaved
123 class User extends Spine.Model
133 .on 'save' # create / update
134 .on 'change' # create / update / destroy
137 .on 'error' # validation error
143 class User extends Spine.Model
144 @extend Spine.Model.Ajax
155 user.url() #=> "/users"
156 user.url('bands') #=> "/users/bands"
159 user.url() #=> "/admin/users"
163 Spine.Model.host = 'http://endpoint'
167 read → GET /collection
168 create → POST /collection (201 created)
169 update → PUT /collection/id
170 destroy → DELETE /collection/id
174 class Photo extends Spine.Model
175 @belongsTo 'album', 'Album' # window['Album']
176 @belongsTo 'album', 'models/album' # via require.js
179 @hasMany 'photos', 'models/photo'
182 album.photos().create(name: "Vacation")
183 album.photos().find(id)
185 photo = Photo.create(album: album)