Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #132 from hippich/pk-model-tojson
Browse files Browse the repository at this point in the history
Use model.toJSON() when available to retrieve model content

Fixes #131
  • Loading branch information
nilbus committed Feb 3, 2015
2 parents fdd876f + 776714b commit 35ca797
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 92 deletions.
26 changes: 13 additions & 13 deletions backbone.dualstorage.amd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions backbone.dualstorage.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,18 @@ class window.Store

# Add a model, giving it a unique GUID, if it doesn't already
# have an id of it's own.
create: (model) ->
create: (model, options) ->
if not _.isObject(model) then return model
if not model.id
model.set model.idAttribute, @generateId()
localStorage.setItem @name + @sep + model.id, JSON.stringify(model)
localStorage.setItem @name + @sep + model.id, JSON.stringify(if model.toJSON then model.toJSON(options) else model)
@records.push model.id.toString()
@save()
model

# Update a model by replacing its copy in `this.data`.
update: (model) ->
localStorage.setItem @name + @sep + model.id, JSON.stringify(model)
update: (model, options) ->
localStorage.setItem @name + @sep + model.id, JSON.stringify(if model.toJSON then model.toJSON(options) else model)
if not _.include(@records, model.id.toString())
@records.push model.id.toString()
@save()
Expand Down Expand Up @@ -194,11 +194,11 @@ localsync = (method, model, options) ->
if options.add and not options.merge and (preExisting = store.find(model))
preExisting
else
model = store.create(model)
model = store.create(model, options)
store.dirty(model) if options.dirty
model
when 'update'
store.update(model)
store.update(model, options)
if options.dirty
store.dirty(model)
else
Expand Down
26 changes: 13 additions & 13 deletions backbone.dualstorage.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions spec/backbone.dualstorage.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions spec/backbone_extensions_spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions spec/bugs_spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions spec/dualsync_spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions spec/integration_spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 35ca797

Please sign in to comment.