Commit dc165887 authored by akiraohgaki's avatar akiraohgaki

Update chirit

parent 4b63e8b7
......@@ -8,7 +8,7 @@
*/
import Component from './Component.js';
import StatusManager from './StatusManager.js';
import StateManager from './StateManager.js';
import WebStorage from './WebStorage.js';
import Utility from './Utility.js';
......@@ -18,8 +18,8 @@ export default class Chirit {
return Component;
}
static get StatusManager() {
return StatusManager;
static get StateManager() {
return StateManager;
}
static get WebStorage() {
......
......@@ -11,7 +11,7 @@ export default class Component {
// Subclass should use init() instead of constructor()
constructor(element, state) {
// "element" will be Element object or selector string
// "element" should be Element object or selector string
if (typeof element === 'string') {
element = document.querySelector(element);
}
......
......@@ -7,10 +7,10 @@
* @link https://github.com/akiraohgaki/chirit
*/
export default class StatusManager {
export default class StateManager {
constructor(eventTarget) {
// "eventTarget" will be Element object or selector string
// "eventTarget" should be Element object or selector string
if (typeof eventTarget === 'string') {
eventTarget = document.querySelector(eventTarget);
}
......@@ -22,23 +22,23 @@ export default class StatusManager {
this.dispatch(event.type, event.detail);
};
this._status = new Map();
this._states = new Map();
this._actions = new Map();
this._views = new Map();
}
getStatus() {
return this._status;
getStates() {
return this._states;
}
getState(type) {
return this._status.get(type);
return this._states.get(type);
}
registerAction(type, action, options) {
const actions = this._actions.has(type) ? this._actions.get(type) : new Map();
if (!actions.size) {
this._status.set(type, {});
this._states.set(type, {});
this._eventTarget.addEventListener(type, this._eventListener, false);
}
actions.set(action, options);
......@@ -55,7 +55,7 @@ export default class StatusManager {
}
else {
this._actions.delete(type);
this._status.delete(type);
this._states.delete(type);
this._eventTarget.removeEventListener(type, this._eventListener, false);
}
}
......@@ -98,12 +98,12 @@ export default class StatusManager {
}
Promise.all(promises)
.then((status) => {
.then((states) => {
const state = {};
for (const _state of status) {
for (const _state of states) {
Object.assign(state, _state);
}
this._status.set(type, state);
this._states.set(type, state);
if (!this._views.has(type)) {
console.log(`No views for type "${type}"`); // This case is not error
......
......@@ -67,7 +67,7 @@ export default class Utility {
}
static convertDatetimeToHumanReadable(datetime) {
// Must be datetime in ISO 8601 format
// "datetime" should be ISO 8601 formatted string
const minute = 60 * 1000;
const hour = 60 * minute;
......
......@@ -10,7 +10,7 @@
export default class WebStorage {
constructor(type = 'session', prefix = '') {
// "type" will be set 'session' or 'local'
// "type" should be "session" or "local"
this._storage = (type === 'local') ? window.localStorage : window.sessionStorage;
this._prefix = prefix;
}
......
{
"name": "chirit",
"version": "0.2.1",
"version": "0.3.0",
"description": "A front-end library.",
"author": "Akira Ohgaki",
"license": "BSD-2-Clause",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment