Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
vrde
committed
Nov 1, 2016
1 parent
6a9421d
commit 72d9f70
Showing
5 changed files
with
82 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,60 @@ | ||
import { isEmpty } from '../utils'; | ||
import $ from 'jquery'; | ||
|
||
import { isEmpty, isFunction } from '../utils'; | ||
|
||
const backend = chrome.storage.sync; | ||
|
||
export function get (key, setIfMissing) { | ||
return new Promise((resolve, reject) => { | ||
chrome.storage.sync.get(userId, (record) => { | ||
if (isEmpty(record)) { | ||
if (isFunction(setIfMissing)) { | ||
|
||
} | ||
backend.get(key, val => { | ||
if (chrome.runtime.lastError) { | ||
reject(chrome.runtime.lastError); | ||
} else if (isEmpty(val)) { | ||
var newVal = isFunction(setIfMissing) ? setIfMissing(key) : setIfMissing; | ||
backend.set(newVal, () => resolve(newVal)); | ||
} else { | ||
resolve(val[key]); | ||
} | ||
}); | ||
}) | ||
}); | ||
} | ||
|
||
export function set (key, value) { | ||
return new Promise((resolve, reject) => { | ||
}) | ||
var newVal = {}; | ||
newVal[key] = isFunction(value) ? value(key) : value; | ||
backend.set(newVal, () => { | ||
if (chrome.runtime.lastError) { | ||
reject(chrome.runtime.lastError); | ||
} else { | ||
resolve(newVal[key]); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
export function update (key, value) { | ||
return new Promise((resolve, reject) => { | ||
}) | ||
} | ||
|
||
export function delete (key) { | ||
get(key) | ||
.then(oldVal => { | ||
var newVal; | ||
if (isFunction(value)) { | ||
newVal = value(oldVal); | ||
} else { | ||
newVal = $.extend(true, oldVal, value); | ||
} | ||
set(key, newVal) | ||
.then(val => resolve(val)) | ||
.catch(error => reject(error)); | ||
}) | ||
.catch(error => reject(error)); | ||
}); | ||
}; | ||
|
||
} | ||
export function remove (key) { | ||
return new Promise((resolve, reject) => { | ||
backend.remove(key) | ||
.then(val => resolve(val)) | ||
.catch(error => reject(error)); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters