|
|
|
@ -1,3 +1,4 @@ |
|
|
|
|
/* global localStorage */ |
|
|
|
|
import { EventEmitter } from 'events' |
|
|
|
|
|
|
|
|
|
export class Store { |
|
|
|
@ -28,12 +29,12 @@ export class Store { |
|
|
|
|
|
|
|
|
|
/** Listen on event from the store */ |
|
|
|
|
get on () { |
|
|
|
|
return this.event.on; |
|
|
|
|
return this.event.on |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** Liste once on event from the store */ |
|
|
|
|
get once () { |
|
|
|
|
return this.event.once; |
|
|
|
|
return this.event.once |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -74,8 +75,6 @@ export class Store { |
|
|
|
|
* @property {Object} entities A map of ids and entities |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class EntityStore extends Store { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -94,13 +93,11 @@ export class EntityStore extends Store { |
|
|
|
|
* @param {string} name The name of the store |
|
|
|
|
* @param {EntityState} initialState The initial state used if state is not available in `localStorage` |
|
|
|
|
*/ |
|
|
|
|
/* |
|
|
|
|
constructor (name, initialState) { |
|
|
|
|
super(name, initialState) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
////////////
|
|
|
|
|
// GETTER //
|
|
|
|
|
////////////
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
/** Tne entities as a Map */ |
|
|
|
|
get entities () { |
|
|
|
@ -122,10 +119,6 @@ export class EntityStore extends Store { |
|
|
|
|
return this.state.ids.length |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/////////////
|
|
|
|
|
// SETTERS //
|
|
|
|
|
/////////////
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Add a new entity to the state |
|
|
|
|
* @param {Object} entity |
|
|
|
@ -216,10 +209,6 @@ export class EntityStore extends Store { |
|
|
|
|
return this.state.actives.map(id => this.state.entities[id]) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
|
// CONDITIONS //
|
|
|
|
|
////////////////
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Is the entity active |
|
|
|
|
* @param {(string|number)} id The id of the entity to check |
|
|
|
@ -249,6 +238,7 @@ export class EntityStore extends Store { |
|
|
|
|
* Store the state of the stores into LocalStorage |
|
|
|
|
* @param {Store[]} stores The list of stores to store into `localStorage` |
|
|
|
|
*/ |
|
|
|
|
/* |
|
|
|
|
function localState (stores) { |
|
|
|
|
stores.forEach(store => { |
|
|
|
|
const name = store.name |
|
|
|
@ -257,3 +247,4 @@ function localState(stores) { |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|