Upgrade to spinejs 1.5.0.

This commit is contained in:
Martin Edenhofer 2015-05-25 01:44:15 +02:00
parent 696f2174de
commit 7f7312129c
4 changed files with 20 additions and 21 deletions

View file

@ -212,7 +212,7 @@ class Singleton extends Base
(data, status, xhr) =>
Ajax.disable =>
unless Spine.isBlank(data) or @record.destroyed
unless data is undefined or Object.getOwnPropertyNames(data).length == 0 or @record.destroyed
# Update with latest data
@record.refresh(data)

View file

@ -2,6 +2,13 @@ Spine = @Spine or require('spine')
Spine.Model.Local =
extended: ->
testLocalStorage = 'spine' + new Date().getTime()
try
localStorage.setItem(testLocalStorage, testLocalStorage)
localStorage.removeItem(testLocalStorage)
catch e
return
@change @saveLocal
@fetch @loadLocal

View file

@ -1,5 +1,4 @@
Spine = @Spine or require('spine')
isArray = Spine.isArray
class Collection extends Spine.Module
constructor: (options = {}) ->
@ -42,7 +41,7 @@ class Collection extends Spine.Module
for match, i in @model.records when match.id is record.id
@model.records.splice(i, 1)
break
values = [values] unless isArray(values)
values = [values] unless Array.isArray(values)
for record in values
record.newRecord = false
record[@fkey] = @record.id
@ -104,7 +103,7 @@ underscore = (str) ->
str.replace(/::/g, '/')
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
.replace(/([a-z\d])([A-Z])/g, '$1_$2')
.replace(/-/g, '_')
.replace(/(-|\.)/g, '_')
.toLowerCase()
requireModel = (model) ->

View file

@ -160,19 +160,22 @@ class Model extends Module
@exists: (id) -> Boolean @irecords[id]
@addRecord: (record) ->
@addRecord: (record,idx) ->
if root = @irecords[record.id or record.cid]
root.refresh(record)
else
record.id or= record.cid
@irecords[record.id] = @irecords[record.cid] = record
@records.push(record)
if idx isnt undefined
@records.splice(idx,0,record)
else
@records.push(record)
record
@refresh: (values, options = {}) ->
@deleteAll() if options.clear
records = @fromJSON(values)
records = [records] unless isArray(records)
records = [records] unless Array.isArray(records)
@addRecord(record) for record in records
@sort()
@ -256,7 +259,7 @@ class Model extends Module
if typeof objects is 'string'
objects = JSON.parse(objects)
objects = @beforeFromJSON(objects)
if isArray(objects)
if Array.isArray(objects)
for value in objects
if value instanceof this
value
@ -464,7 +467,7 @@ class Model extends Module
@id or= @cid
record = @dup(false)
@constructor.addRecord(record)
@constructor.addRecord(record,options.idx)
@constructor.sort()
clone = record.clone()
@ -610,14 +613,6 @@ createObject = Object.create or (o) ->
Func.prototype = o
new Func()
isArray = (value) ->
Object::toString.call(value) is '[object Array]'
isBlank = (value) ->
return true unless value
return false for key of value
true
makeArray = (args) ->
Array::slice.call(args, 0)
@ -626,9 +621,7 @@ makeArray = (args) ->
Spine = @Spine = {}
module?.exports = Spine
Spine.version = '1.4.1'
Spine.isArray = isArray
Spine.isBlank = isBlank
Spine.version = '1.5.0'
Spine.$ = $
Spine.Events = Events
Spine.Log = Log