Upgrade to spinejs 1.3.2.
This commit is contained in:
parent
eed3467de0
commit
2ab5448480
8 changed files with 31 additions and 25 deletions
0
app/assets/javascripts/app/lib/spine/ajax.coffee
Executable file → Normal file
0
app/assets/javascripts/app/lib/spine/ajax.coffee
Executable file → Normal file
0
app/assets/javascripts/app/lib/spine/bindings.coffee
Executable file → Normal file
0
app/assets/javascripts/app/lib/spine/bindings.coffee
Executable file → Normal file
0
app/assets/javascripts/app/lib/spine/list.coffee
Executable file → Normal file
0
app/assets/javascripts/app/lib/spine/list.coffee
Executable file → Normal file
0
app/assets/javascripts/app/lib/spine/local.coffee
Executable file → Normal file
0
app/assets/javascripts/app/lib/spine/local.coffee
Executable file → Normal file
0
app/assets/javascripts/app/lib/spine/manager.coffee
Executable file → Normal file
0
app/assets/javascripts/app/lib/spine/manager.coffee
Executable file → Normal file
9
app/assets/javascripts/app/lib/spine/relation.coffee
Executable file → Normal file
9
app/assets/javascripts/app/lib/spine/relation.coffee
Executable file → Normal file
|
@ -1,6 +1,5 @@
|
|||
Spine = @Spine or require('spine')
|
||||
isArray = Spine.isArray
|
||||
require = @require or ((value) -> eval(value))
|
||||
|
||||
class Collection extends Spine.Module
|
||||
constructor: (options = {}) ->
|
||||
|
@ -111,8 +110,14 @@ underscore = (str) ->
|
|||
.replace(/-/g, '_')
|
||||
.toLowerCase()
|
||||
|
||||
requireModel = (model) ->
|
||||
if typeof model is 'string'
|
||||
require?(model) or eval(model)
|
||||
else
|
||||
model
|
||||
|
||||
association = (name, model, record, fkey, Ctor) ->
|
||||
model = require(model) if typeof model is 'string'
|
||||
model = requireModel(model) if typeof model is 'string'
|
||||
new Ctor(name: name, model: model, record: record, fkey: fkey)
|
||||
|
||||
Spine.Model.extend
|
||||
|
|
30
app/assets/javascripts/app/lib/spine/route.coffee
Executable file → Normal file
30
app/assets/javascripts/app/lib/spine/route.coffee
Executable file → Normal file
|
@ -71,6 +71,9 @@ class Route extends Spine.Module
|
|||
@change()
|
||||
|
||||
@unbind: ->
|
||||
unbindResult = Spine.Events.unbind.apply this, arguments
|
||||
return unbindResult if arguments.length > 0
|
||||
|
||||
return if @options.shim
|
||||
|
||||
if @history
|
||||
|
@ -80,33 +83,30 @@ class Route extends Spine.Module
|
|||
|
||||
@navigate: (args...) ->
|
||||
options = {}
|
||||
|
||||
lastArg = args[args.length - 1]
|
||||
if typeof lastArg is 'object'
|
||||
options = args.pop()
|
||||
else if typeof lastArg is 'boolean'
|
||||
options.trigger = args.pop()
|
||||
|
||||
options = $.extend({}, @options, options)
|
||||
|
||||
path = args.join('/')
|
||||
return if @path is path
|
||||
@path = path
|
||||
|
||||
@trigger('navigate', @path)
|
||||
if options.trigger
|
||||
@trigger('navigate', @path)
|
||||
routes = @matchRoutes(@path, options)
|
||||
unless routes.length
|
||||
if typeof options.redirect is 'function'
|
||||
return options.redirect.apply this, [@path, options]
|
||||
else
|
||||
if options.redirect is true
|
||||
@redirect(@path)
|
||||
|
||||
routes = @matchRoutes(@path, options) if options.trigger
|
||||
|
||||
return if options.shim
|
||||
|
||||
unless routes.length
|
||||
if typeof options.redirect is 'function'
|
||||
return options.redirect.apply this, [@path, options]
|
||||
else
|
||||
if options.redirect is true
|
||||
@redirect(@path)
|
||||
|
||||
if @history and options.replace
|
||||
if options.shim
|
||||
true
|
||||
else if @history and options.replace
|
||||
history.replaceState({}, document.title, @path)
|
||||
else if @history
|
||||
history.pushState({}, document.title, @path)
|
||||
|
|
17
app/assets/javascripts/app/lib/spine/spine.coffee
Executable file → Normal file
17
app/assets/javascripts/app/lib/spine/spine.coffee
Executable file → Normal file
|
@ -149,13 +149,14 @@ class Model extends Module
|
|||
@toString: -> "#{@className}(#{@attributes.join(", ")})"
|
||||
|
||||
@find: (id, notFound = @notFound) ->
|
||||
record = @irecords[id]?.clone()
|
||||
return record or notFound?(id)
|
||||
@irecords[id]?.clone() or notFound?(id)
|
||||
|
||||
@notFound: (id) -> return null
|
||||
@findAll: (ids, notFound) ->
|
||||
(@find(id) for id in ids when @find(id, notFound))
|
||||
|
||||
@exists: (id) ->
|
||||
return if @irecords[id] then true else false
|
||||
@notFound: (id) -> null
|
||||
|
||||
@exists: (id) -> Boolean @irecords[id]
|
||||
|
||||
@addRecord: (record, options = {}) ->
|
||||
if record.id and @irecords[record.id]
|
||||
|
@ -321,8 +322,8 @@ class Model extends Module
|
|||
result
|
||||
|
||||
eql: (rec) ->
|
||||
!!(rec and rec.constructor is @constructor and
|
||||
((rec.cid is @cid) or (rec.id and rec.id is @id)))
|
||||
rec and rec.constructor is @constructor and
|
||||
((rec.cid is @cid) or (rec.id and rec.id is @id))
|
||||
|
||||
save: (options = {}) ->
|
||||
unless options.validate is false
|
||||
|
@ -634,7 +635,7 @@ makeArray = (args) ->
|
|||
Spine = @Spine = {}
|
||||
module?.exports = Spine
|
||||
|
||||
Spine.version = '1.3.1'
|
||||
Spine.version = '1.3.2'
|
||||
Spine.isArray = isArray
|
||||
Spine.isBlank = isBlank
|
||||
Spine.$ = $
|
||||
|
|
Loading…
Reference in a new issue