adding dev files to master
adding all the dev files, package, webpack etc, including build which will contain minified release
This commit is contained in:
51
src/helpers/PersistentSyncStorage.js
Normal file
51
src/helpers/PersistentSyncStorage.js
Normal file
@@ -0,0 +1,51 @@
|
||||
import { SyncStorage } from '../utils/chrome';
|
||||
import { EventEmitter } from 'events';
|
||||
|
||||
class PersistentSyncStorage extends EventEmitter {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this._data = null;
|
||||
this.state = 'initiating';
|
||||
|
||||
this._init();
|
||||
}
|
||||
|
||||
async _init() {
|
||||
const fetchedData = await SyncStorage.get();
|
||||
this._initListener();
|
||||
this._data = fetchedData;
|
||||
this.state = 'ready';
|
||||
this.emit(this.state);
|
||||
}
|
||||
|
||||
_initListener() {
|
||||
SyncStorage.listen((changes) => {
|
||||
|
||||
Object.keys(changes).forEach((changeKey) => {
|
||||
if(changes[changeKey].hasOwnProperty('newValue')) {
|
||||
this._data[changeKey] = changes[changeKey].newValue;
|
||||
} else {
|
||||
console.error('No newValue in sync storge change');
|
||||
}
|
||||
});
|
||||
|
||||
this.emit('change', this.data, changes);
|
||||
});
|
||||
}
|
||||
|
||||
set(items) {
|
||||
return SyncStorage.set(items);
|
||||
}
|
||||
|
||||
get data() {
|
||||
return this._data;
|
||||
}
|
||||
|
||||
|
||||
has(item) {
|
||||
return this.data.hasOwnProperty(item);
|
||||
}
|
||||
}
|
||||
|
||||
export default new PersistentSyncStorage();
|
||||
Reference in New Issue
Block a user