Skip to content

Commit

Permalink
Remove extraneous serialized. Fix init error propagation.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukesmurray committed Jan 23, 2019
1 parent 4c78b8a commit 87087a1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var json = _.JSON = $.Class({
extends: _.Base,
static: {
parse: serialized => Promise.resolve(serialized && (serialized + "").trim() ?
JSON.parse((serialized + "").trim()) : null),
JSON.parse(serialized) : null),
stringify: data => Promise.resolve(Mavo.toJSON(data)),
extensions: [".json", ".jsonld"]
}
Expand Down
12 changes: 7 additions & 5 deletions src/mavo.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,19 +475,21 @@ var _ = self.Mavo = $.Class({

return backend.ready.then(() => backend.load())
.then(data => {
// if we get null data try to load from init
// if we get null data throw an error
return data === null? Promise.reject(new Error('backend loaded null data')) : data;
})
.catch(err => {
// if we get an error try to load from init
// Try again with init
// if there is an init backend then return null and don't propagate the error
if (this.init && this.init != backend) {
backend = this.init;
return this.init.ready.then(() => this.init.load());
return null;
}

// No init, propagate error
return Promise.reject(err);
return Promise.reject(err);
}).then(data => {
// if data is null we have an init backend so try to load from the init backend
return data === null ? this.init.ready.then(() => this.init.load()) : data;
})
.catch(err => {
if (err) {
Expand Down

0 comments on commit 87087a1

Please sign in to comment.