Upgrade to spinejs 1.5.0.
This commit is contained in:
parent
696f2174de
commit
7f7312129c
4 changed files with 20 additions and 21 deletions
|
@ -212,7 +212,7 @@ class Singleton extends Base
|
||||||
(data, status, xhr) =>
|
(data, status, xhr) =>
|
||||||
|
|
||||||
Ajax.disable =>
|
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
|
# Update with latest data
|
||||||
@record.refresh(data)
|
@record.refresh(data)
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,13 @@ Spine = @Spine or require('spine')
|
||||||
|
|
||||||
Spine.Model.Local =
|
Spine.Model.Local =
|
||||||
extended: ->
|
extended: ->
|
||||||
|
testLocalStorage = 'spine' + new Date().getTime()
|
||||||
|
try
|
||||||
|
localStorage.setItem(testLocalStorage, testLocalStorage)
|
||||||
|
localStorage.removeItem(testLocalStorage)
|
||||||
|
catch e
|
||||||
|
return
|
||||||
|
|
||||||
@change @saveLocal
|
@change @saveLocal
|
||||||
@fetch @loadLocal
|
@fetch @loadLocal
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
Spine = @Spine or require('spine')
|
Spine = @Spine or require('spine')
|
||||||
isArray = Spine.isArray
|
|
||||||
|
|
||||||
class Collection extends Spine.Module
|
class Collection extends Spine.Module
|
||||||
constructor: (options = {}) ->
|
constructor: (options = {}) ->
|
||||||
|
@ -42,7 +41,7 @@ class Collection extends Spine.Module
|
||||||
for match, i in @model.records when match.id is record.id
|
for match, i in @model.records when match.id is record.id
|
||||||
@model.records.splice(i, 1)
|
@model.records.splice(i, 1)
|
||||||
break
|
break
|
||||||
values = [values] unless isArray(values)
|
values = [values] unless Array.isArray(values)
|
||||||
for record in values
|
for record in values
|
||||||
record.newRecord = false
|
record.newRecord = false
|
||||||
record[@fkey] = @record.id
|
record[@fkey] = @record.id
|
||||||
|
@ -104,7 +103,7 @@ underscore = (str) ->
|
||||||
str.replace(/::/g, '/')
|
str.replace(/::/g, '/')
|
||||||
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
|
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
|
||||||
.replace(/([a-z\d])([A-Z])/g, '$1_$2')
|
.replace(/([a-z\d])([A-Z])/g, '$1_$2')
|
||||||
.replace(/-/g, '_')
|
.replace(/(-|\.)/g, '_')
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
|
|
||||||
requireModel = (model) ->
|
requireModel = (model) ->
|
||||||
|
|
|
@ -160,19 +160,22 @@ class Model extends Module
|
||||||
|
|
||||||
@exists: (id) -> Boolean @irecords[id]
|
@exists: (id) -> Boolean @irecords[id]
|
||||||
|
|
||||||
@addRecord: (record) ->
|
@addRecord: (record,idx) ->
|
||||||
if root = @irecords[record.id or record.cid]
|
if root = @irecords[record.id or record.cid]
|
||||||
root.refresh(record)
|
root.refresh(record)
|
||||||
else
|
else
|
||||||
record.id or= record.cid
|
record.id or= record.cid
|
||||||
@irecords[record.id] = @irecords[record.cid] = record
|
@irecords[record.id] = @irecords[record.cid] = record
|
||||||
|
if idx isnt undefined
|
||||||
|
@records.splice(idx,0,record)
|
||||||
|
else
|
||||||
@records.push(record)
|
@records.push(record)
|
||||||
record
|
record
|
||||||
|
|
||||||
@refresh: (values, options = {}) ->
|
@refresh: (values, options = {}) ->
|
||||||
@deleteAll() if options.clear
|
@deleteAll() if options.clear
|
||||||
records = @fromJSON(values)
|
records = @fromJSON(values)
|
||||||
records = [records] unless isArray(records)
|
records = [records] unless Array.isArray(records)
|
||||||
@addRecord(record) for record in records
|
@addRecord(record) for record in records
|
||||||
@sort()
|
@sort()
|
||||||
|
|
||||||
|
@ -256,7 +259,7 @@ class Model extends Module
|
||||||
if typeof objects is 'string'
|
if typeof objects is 'string'
|
||||||
objects = JSON.parse(objects)
|
objects = JSON.parse(objects)
|
||||||
objects = @beforeFromJSON(objects)
|
objects = @beforeFromJSON(objects)
|
||||||
if isArray(objects)
|
if Array.isArray(objects)
|
||||||
for value in objects
|
for value in objects
|
||||||
if value instanceof this
|
if value instanceof this
|
||||||
value
|
value
|
||||||
|
@ -464,7 +467,7 @@ class Model extends Module
|
||||||
@id or= @cid
|
@id or= @cid
|
||||||
|
|
||||||
record = @dup(false)
|
record = @dup(false)
|
||||||
@constructor.addRecord(record)
|
@constructor.addRecord(record,options.idx)
|
||||||
@constructor.sort()
|
@constructor.sort()
|
||||||
|
|
||||||
clone = record.clone()
|
clone = record.clone()
|
||||||
|
@ -610,14 +613,6 @@ createObject = Object.create or (o) ->
|
||||||
Func.prototype = o
|
Func.prototype = o
|
||||||
new Func()
|
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) ->
|
makeArray = (args) ->
|
||||||
Array::slice.call(args, 0)
|
Array::slice.call(args, 0)
|
||||||
|
|
||||||
|
@ -626,9 +621,7 @@ makeArray = (args) ->
|
||||||
Spine = @Spine = {}
|
Spine = @Spine = {}
|
||||||
module?.exports = Spine
|
module?.exports = Spine
|
||||||
|
|
||||||
Spine.version = '1.4.1'
|
Spine.version = '1.5.0'
|
||||||
Spine.isArray = isArray
|
|
||||||
Spine.isBlank = isBlank
|
|
||||||
Spine.$ = $
|
Spine.$ = $
|
||||||
Spine.Events = Events
|
Spine.Events = Events
|
||||||
Spine.Log = Log
|
Spine.Log = Log
|
||||||
|
|
Loading…
Reference in a new issue