Skip to content

Commit

Permalink
style: standard
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Feb 19, 2018
1 parent e797c22 commit e9ceb07
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 53 deletions.
86 changes: 43 additions & 43 deletions lib/init.js
Expand Up @@ -27,30 +27,30 @@ function init (hoodie) {

return hoodie.store.reset()

.then(function () {
function migrate (doc) {
doc.createdBy = account.id
delete doc._rev
return doc
}
return hoodie.store.add(options.beforeSignin.docs.map(migrate))
})

.then(function () {
return hoodie.store.connect()
})
.then(function () {
function migrate (doc) {
doc.createdBy = account.id
delete doc._rev
return doc
}
return hoodie.store.add(options.beforeSignin.docs.map(migrate))
})

.then(function () {
return hoodie.store.connect()
})
})

hoodie.account.hook.before('signout', function () {
return hoodie.store.push()
.catch(function (error) {
if (error.status !== 401) {
throw error
}
.catch(function (error) {
if (error.status !== 401) {
throw error
}

error.message = 'Local changes could not be synced, sign in first'
throw error
})
error.message = 'Local changes could not be synced, sign in first'
throw error
})
})
hoodie.account.hook.after('signout', function (options) {
return hoodie.store.reset()
Expand All @@ -63,40 +63,40 @@ function init (hoodie) {
hoodie.connectionStatus.on('disconnect', function () {
hoodie.account.get('session')

.then(function (session) {
if (session) {
hoodie.store.disconnect()
}
})
.then(function (session) {
if (session) {
hoodie.store.disconnect()
}
})
})
hoodie.connectionStatus.on('reconnect', function () {
hoodie.account.get('session')

.then(function (session) {
if (session) {
hoodie.store.connect()
}
})
.then(function (session) {
if (session) {
hoodie.store.connect()
}
})
})

hoodie.account.get('session')

.then(function (session) {
.then(function (session) {
// signed out
if (!session) {
return
}
if (!session) {
return
}

// signed in, but session was invalid
if (session.invalid) {
return
}
// signed in, but session was invalid
if (session.invalid) {
return
}

// hoodie.connectionStatus.ok is false if there is a connection issue
if (hoodie.connectionStatus.ok === false) {
return
}
// hoodie.connectionStatus.ok is false if there is a connection issue
if (hoodie.connectionStatus.ok === false) {
return
}

hoodie.store.connect()
})
hoodie.store.connect()
})
}
20 changes: 10 additions & 10 deletions tests/specs/init.js
Expand Up @@ -56,13 +56,13 @@ test('"reset" triggered on "signin"', function (t) {
var options = {}
beforeSignInCall.args[1](options)

.then(function () {
options.beforeSignin.accountId = 'accountid2'
return afterSignInCall.args[1]({}, options)
})
.then(function () {
t.deepEqual(signInTestOrder, ['reset', 'connect'], 'store.connect was called after store.reset')
})
.then(function () {
options.beforeSignin.accountId = 'accountid2'
return afterSignInCall.args[1]({}, options)
})
.then(function () {
t.deepEqual(signInTestOrder, ['reset', 'connect'], 'store.connect was called after store.reset')
})
})

test('"reset" triggered after signout', function (t) {
Expand Down Expand Up @@ -515,9 +515,9 @@ test('hoodie.store.connect() is called', function (t) {
var options = {}
beforeSignInCall.args[1](options)

.then(function () {
return afterSignInCall.args[1](hoodie.account, options)
})
.then(function () {
return afterSignInCall.args[1](hoodie.account, options)
})
})
test('hoodie.account.hook.before returns an error', function (t) {
t.plan(2)
Expand Down

0 comments on commit e9ceb07

Please sign in to comment.