Skip to content
This repository was archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
diracdeltas committed Feb 18, 2017
1 parent b7e0781 commit cce94a0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
21 changes: 11 additions & 10 deletions app/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ const doAction = (sender, action) => {
* @param {Event} e
*/
module.exports.onSyncReady = (isFirstRun, e) => {
initialized = true
if (!syncEnabled()) {
return
}
if (isFirstRun) {
if (!initialized && isFirstRun) {
initialized = true
// Sync the device id for this device
sendSyncRecords(e.sender, writeActions.CREATE, [{
name: 'device',
Expand Down Expand Up @@ -301,7 +301,7 @@ module.exports.init = function (initialState) {
}
})
ipcMain.on(messages.SYNC_READY, module.exports.onSyncReady.bind(null,
initialized ? false : !initialState.seed && !initialState.deviceId))
!initialState.seed && !initialState.deviceId))
ipcMain.on(messages.SYNC_DEBUG, (e, msg) => {
log(msg)
})
Expand All @@ -324,18 +324,19 @@ module.exports.init = function (initialState) {
if (!records || !records.length) {
return
}
let showBookmarksToolbar = false
if (!initialState.seed) {
// syncing for the first time
const bookmarks = (AppStore.getState().get('sites') || new Immutable.List()).filter((site) => {
const tags = site.get('tags')
return tags && (tags.includes('bookmark') || tags.includes('bookmark-folder'))
})
const bookmarks = siteUtil.getBookmarks(AppStore.getState().get('sites'))
if (!bookmarks.size) {
showBookmarksToolbar = true
for (const record of records) {
if (record && record.objectData === 'bookmark') {
appActions.changeSetting(settings.SHOW_BOOKMARKS_TOOLBAR, true)
break
}
}
}
}
syncUtil.applySyncRecords(records, showBookmarksToolbar)
syncUtil.applySyncRecords(records)
})
}

Expand Down
19 changes: 6 additions & 13 deletions js/state/syncUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
const Immutable = require('immutable')
const writeActions = require('../constants/sync/proto').actions
const siteUtil = require('./siteUtil')
const settings = require('../constants/settings')

const CATEGORY_MAP = {
bookmark: {
Expand Down Expand Up @@ -55,10 +54,9 @@ const pickFields = (object, fields) => {
/**
* Apply a bookmark or historySite SyncRecord to the browser data store.
* @param {Object} record
* @param {boolean} showBookmarksToolbar
* @param {Immutable.Map} siteDetail
*/
const applySiteRecord = (record, showBookmarksToolbar = false) => {
const applySiteRecord = (record) => {
const appActions = require('../actions/appActions')
const siteTags = require('../constants/siteTags')
const objectId = new Immutable.List(record.objectId)
Expand Down Expand Up @@ -97,9 +95,6 @@ const applySiteRecord = (record, showBookmarksToolbar = false) => {
switch (record.action) {
case writeActions.CREATE:
appActions.addSite(siteDetail, tag, undefined, undefined, true)
if (showBookmarksToolbar && record.objectData === 'bookmark') {
appActions.changeSetting(settings.SHOW_BOOKMARKS_TOOLBAR, true)
}
break
case writeActions.UPDATE:
appActions.addSite(siteDetail, tag, existingObjectData, null, true)
Expand Down Expand Up @@ -171,17 +166,16 @@ const applySiteSettingRecord = (record) => {
/**
* Given a SyncRecord, apply it to the browser data store.
* @param {Object} record
* @param {boolean} showBookmarksToolbar
*/
module.exports.applySyncRecord = (record, showBookmarksToolbar) => {
module.exports.applySyncRecord = (record) => {
if (!record || !record.objectData) {
console.log(`Warning: Can't apply empty record: ${record}`)
return
}
switch (record.objectData) {
case 'bookmark':
case 'historySite':
applySiteRecord(record, showBookmarksToolbar)
applySiteRecord(record)
break
case 'siteSetting':
applySiteSettingRecord(record)
Expand All @@ -197,14 +191,13 @@ module.exports.applySyncRecord = (record, showBookmarksToolbar) => {
/**
* Apply several SyncRecords in a less blocking manner.
* @param {Array<Object>} records
* @param {boolean} showBookmarksToolbar
*/
module.exports.applySyncRecords = (records, showBookmarksToolbar) => {
module.exports.applySyncRecords = (records) => {
if (!records || records.length === 0) { return }
setImmediate(() => {
const record = records.shift()
module.exports.applySyncRecord(record, showBookmarksToolbar)
module.exports.applySyncRecords(records, showBookmarksToolbar)
module.exports.applySyncRecord(record)
module.exports.applySyncRecords(records)
})
}

Expand Down

0 comments on commit cce94a0

Please sign in to comment.