Upgrade to spinejs 1.3.2.

This commit is contained in:
Martin Edenhofer 2014-08-31 17:46:42 +02:00
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
View file

0
app/assets/javascripts/app/lib/spine/bindings.coffee Executable file → Normal file
View file

0
app/assets/javascripts/app/lib/spine/list.coffee Executable file → Normal file
View file

0
app/assets/javascripts/app/lib/spine/local.coffee Executable file → Normal file
View file

0
app/assets/javascripts/app/lib/spine/manager.coffee Executable file → Normal file
View file

9
app/assets/javascripts/app/lib/spine/relation.coffee Executable file → Normal file
View file

@ -1,6 +1,5 @@
Spine = @Spine or require('spine') Spine = @Spine or require('spine')
isArray = Spine.isArray isArray = Spine.isArray
require = @require or ((value) -> eval(value))
class Collection extends Spine.Module class Collection extends Spine.Module
constructor: (options = {}) -> constructor: (options = {}) ->
@ -111,8 +110,14 @@ underscore = (str) ->
.replace(/-/g, '_') .replace(/-/g, '_')
.toLowerCase() .toLowerCase()
requireModel = (model) ->
if typeof model is 'string'
require?(model) or eval(model)
else
model
association = (name, model, record, fkey, Ctor) -> 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) new Ctor(name: name, model: model, record: record, fkey: fkey)
Spine.Model.extend Spine.Model.extend

30
app/assets/javascripts/app/lib/spine/route.coffee Executable file → Normal file
View file

@ -71,6 +71,9 @@ class Route extends Spine.Module
@change() @change()
@unbind: -> @unbind: ->
unbindResult = Spine.Events.unbind.apply this, arguments
return unbindResult if arguments.length > 0
return if @options.shim return if @options.shim
if @history if @history
@ -80,33 +83,30 @@ class Route extends Spine.Module
@navigate: (args...) -> @navigate: (args...) ->
options = {} options = {}
lastArg = args[args.length - 1] lastArg = args[args.length - 1]
if typeof lastArg is 'object' if typeof lastArg is 'object'
options = args.pop() options = args.pop()
else if typeof lastArg is 'boolean' else if typeof lastArg is 'boolean'
options.trigger = args.pop() options.trigger = args.pop()
options = $.extend({}, @options, options) options = $.extend({}, @options, options)
path = args.join('/') path = args.join('/')
return if @path is path return if @path is path
@path = 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 if options.shim
true
return if options.shim else if @history and options.replace
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
history.replaceState({}, document.title, @path) history.replaceState({}, document.title, @path)
else if @history else if @history
history.pushState({}, document.title, @path) history.pushState({}, document.title, @path)

17
app/assets/javascripts/app/lib/spine/spine.coffee Executable file → Normal file
View file

@ -149,13 +149,14 @@ class Model extends Module
@toString: -> "#{@className}(#{@attributes.join(", ")})" @toString: -> "#{@className}(#{@attributes.join(", ")})"
@find: (id, notFound = @notFound) -> @find: (id, notFound = @notFound) ->
record = @irecords[id]?.clone() @irecords[id]?.clone() or notFound?(id)
return record or notFound?(id)
@notFound: (id) -> return null @findAll: (ids, notFound) ->
(@find(id) for id in ids when @find(id, notFound))
@exists: (id) -> @notFound: (id) -> null
return if @irecords[id] then true else false
@exists: (id) -> Boolean @irecords[id]
@addRecord: (record, options = {}) -> @addRecord: (record, options = {}) ->
if record.id and @irecords[record.id] if record.id and @irecords[record.id]
@ -321,8 +322,8 @@ class Model extends Module
result result
eql: (rec) -> eql: (rec) ->
!!(rec and rec.constructor is @constructor and rec and rec.constructor is @constructor and
((rec.cid is @cid) or (rec.id and rec.id is @id))) ((rec.cid is @cid) or (rec.id and rec.id is @id))
save: (options = {}) -> save: (options = {}) ->
unless options.validate is false unless options.validate is false
@ -634,7 +635,7 @@ makeArray = (args) ->
Spine = @Spine = {} Spine = @Spine = {}
module?.exports = Spine module?.exports = Spine
Spine.version = '1.3.1' Spine.version = '1.3.2'
Spine.isArray = isArray Spine.isArray = isArray
Spine.isBlank = isBlank Spine.isBlank = isBlank
Spine.$ = $ Spine.$ = $