diff --git a/package-lock.json b/package-lock.json index dffb643..c6f8f8f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -172,14 +172,22 @@ "dev": true }, "babel-code-frame": { - "version": "6.22.0", - "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.22.0.tgz", - "integrity": "sha1-AnYgvuVnqIwyVhV05/0IAdMxGOQ=", + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz", + "integrity": "sha1-Y/1D99weO7fONZR9uP42mj9Yx0s=", "dev": true, "requires": { "chalk": "1.1.3", "esutils": "2.0.2", - "js-tokens": "3.0.1" + "js-tokens": "3.0.2" + }, + "dependencies": { + "js-tokens": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", + "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=", + "dev": true + } } }, "balanced-match": { @@ -421,13 +429,10 @@ "dev": true }, "commander": { - "version": "2.10.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.10.0.tgz", - "integrity": "sha512-q/r9trjmuikWDRJNTBHAVnWhuU6w+z80KgBq7j9YDclik5E7X4xi0KnlZBNFA1zOQ+SH/vHMWd2mC9QTOz7GpA==", - "dev": true, - "requires": { - "graceful-readlink": "1.0.1" - } + "version": "2.11.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.11.0.tgz", + "integrity": "sha512-b0553uYA5YAEGgyYIGYROzKQ7X5RAqedkfjiZxwi0kL1g3bOaBNNZfYkzt/CL0umgD5wc9Jec2FbB98CjkMRvQ==", + "dev": true }, "concat-map": { "version": "0.0.1", @@ -538,9 +543,9 @@ } }, "diff": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/diff/-/diff-3.2.0.tgz", - "integrity": "sha1-yc45Okt8vQsFinJck98pkCeGj/k=", + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/diff/-/diff-3.3.1.tgz", + "integrity": "sha512-MKPHZDMB0o6yHyDryUOScqZibp914ksXwAMYMTHj6KO8UeKsRYNJD3oNCKjTqZon+V488P7N/HzXF8t7ZR95ww==", "dev": true }, "diffie-hellman": { @@ -799,12 +804,6 @@ "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=", "dev": true }, - "graceful-readlink": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/graceful-readlink/-/graceful-readlink-1.0.1.tgz", - "integrity": "sha1-TK+tdrxi8C+gObL5Tpo906ORpyU=", - "dev": true - }, "has-ansi": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", @@ -1654,9 +1653,9 @@ "dev": true }, "resolve": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.3.3.tgz", - "integrity": "sha1-ZVkHw0aahoDcLeOidaj91paR8OU=", + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.4.0.tgz", + "integrity": "sha512-aW7sVKPufyHqOmyyLzg/J+8606v5nevBgaliIlV7nUpVMsDnoBGV/cbSLNjZAg9q0Cfd/+easKVKQ8vOu8fn1Q==", "dev": true, "requires": { "path-parse": "1.0.5" @@ -1868,21 +1867,21 @@ "dev": true }, "tslint": { - "version": "5.4.3", - "resolved": "https://registry.npmjs.org/tslint/-/tslint-5.4.3.tgz", - "integrity": "sha1-dhyEArgONHt3M6BDkKdXslNYBGc=", + "version": "5.7.0", + "resolved": "https://registry.npmjs.org/tslint/-/tslint-5.7.0.tgz", + "integrity": "sha1-wl4NDJL6EgHCvDDoROCOaCtPNVI=", "dev": true, "requires": { - "babel-code-frame": "6.22.0", + "babel-code-frame": "6.26.0", "colors": "1.1.2", - "commander": "2.10.0", - "diff": "3.2.0", + "commander": "2.11.0", + "diff": "3.3.1", "glob": "7.1.2", "minimatch": "3.0.4", - "resolve": "1.3.3", + "resolve": "1.4.0", "semver": "5.3.0", "tslib": "1.7.1", - "tsutils": "2.4.0" + "tsutils": "2.8.2" } }, "tslint-loader": { @@ -1899,10 +1898,13 @@ } }, "tsutils": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.4.0.tgz", - "integrity": "sha1-rUzm26Dlo+2934Ymt8oEB4IYn+o=", - "dev": true + "version": "2.8.2", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.8.2.tgz", + "integrity": "sha1-LBSGukMSYIRbCsb5Aq/Z1wio6mo=", + "dev": true, + "requires": { + "tslib": "1.7.1" + } }, "tty-browserify": { "version": "0.0.0", @@ -1911,9 +1913,9 @@ "dev": true }, "typescript": { - "version": "2.3.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.3.4.tgz", - "integrity": "sha1-PTgyGCgjHkNPKHUUlZw3qCtin0I=", + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.5.2.tgz", + "integrity": "sha1-A4qV99m7tCCxvzW6MdTFwd0//jQ=", "dev": true }, "ua-parser-js": { diff --git a/package.json b/package.json index 168f265..01597a5 100644 --- a/package.json +++ b/package.json @@ -23,9 +23,9 @@ "license": "AGPL-3.0", "devDependencies": { "ts-loader": "^2.1.0", - "tslint": "^5.4.2", + "tslint": "^5.7.0", "tslint-loader": "^3.5.3", - "typescript": "^2.3.4", + "typescript": "^2.5.2", "uglifyjs": "^2.4.11", "webpack": "^2.6.1" }, diff --git a/src/dispatcher.ts b/src/dispatcher.ts index 00c02b6..f6dac54 100644 --- a/src/dispatcher.ts +++ b/src/dispatcher.ts @@ -4,7 +4,7 @@ export interface DispatcherMessage { action: TAction; } -export class DispatcherBuilder extends flux.Dispatcher> { +export class DispatcherClass extends flux.Dispatcher> { /** * Dispatches a payload to all registered callbacks. * @@ -26,4 +26,4 @@ export class DispatcherBuilder extends flux.Dispatcher> { } } -export const Dispatcher = new DispatcherBuilder(); +export const Dispatcher = new DispatcherClass(); diff --git a/src/emmitters/actions-emmitter.ts b/src/emitters/actions-emitter.ts similarity index 100% rename from src/emmitters/actions-emmitter.ts rename to src/emitters/actions-emitter.ts diff --git a/src/helpers.ts b/src/helpers.ts new file mode 100644 index 0000000..8fbbe7a --- /dev/null +++ b/src/helpers.ts @@ -0,0 +1,3 @@ +export { ItemIsPending } from "./helpers/item-is-pending"; +export { ItemsStatusResolver } from "./helpers/items-status-resolver"; +export { WaitForStoreChange } from "./helpers/wait-for-store-change"; diff --git a/src/helpers/item-is-pending.ts b/src/helpers/item-is-pending.ts new file mode 100644 index 0000000..94129dd --- /dev/null +++ b/src/helpers/item-is-pending.ts @@ -0,0 +1,5 @@ +import { ItemStatus } from "../abstractions"; + +export function ItemIsPending(status: ItemStatus): boolean { + return (status <= ItemStatus.Pending); +} diff --git a/src/helpers/items-status-resolver.ts b/src/helpers/items-status-resolver.ts new file mode 100644 index 0000000..f6170a0 --- /dev/null +++ b/src/helpers/items-status-resolver.ts @@ -0,0 +1,33 @@ +import { ItemStatus } from "../abstractions"; + +export function ItemsStatusResolver(...statuses: ItemStatus[]): ItemStatus { + let loadedCount: number = 0; + let noDataCount: number = 0; + let pendingCount: number = 0; + + for (let i = 0; i < statuses.length; i++) { + const status = statuses[i]; + switch (status) { + case ItemStatus.Failed: + return status; + case ItemStatus.Loaded: + loadedCount++; + break; + case ItemStatus.NoData: + noDataCount++; + break; + case ItemStatus.Init: + case ItemStatus.Pending: + pendingCount++; + break; + } + } + + if (pendingCount > 0) { + return ItemStatus.Pending; + } else if (loadedCount === 0 && noDataCount > 0) { + return ItemStatus.NoData; + } else { + return ItemStatus.Loaded; + } +} diff --git a/src/helpers/wait-for-store-change.ts b/src/helpers/wait-for-store-change.ts new file mode 100644 index 0000000..709b3f2 --- /dev/null +++ b/src/helpers/wait-for-store-change.ts @@ -0,0 +1,10 @@ +import { Store } from "flux/utils"; + +export async function WaitForStoreChange(store: Store): Promise { + return new Promise(resolve => { + const listener = store.addListener(() => { + listener.remove(); + resolve(); + }); + }); +} diff --git a/src/index.ts b/src/index.ts index 5012a70..c7216dd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,13 +2,15 @@ export * from "./dispatcher"; export * from "./stores/map-store"; export * from "./stores/data-store"; export * from "./stores/reduce-store"; -export * from "./emmitters/actions-emmitter"; +export * from "./emitters/actions-emitter"; import * as Actions from "./actions/actions"; import * as Abstractions from "./abstractions"; import * as Contracts from "./contracts"; +import * as Helpers from "./helpers"; export { Actions, Abstractions, - Contracts + Contracts, + Helpers }; diff --git a/src/stores/map-store.ts b/src/stores/map-store.ts index 77f879b..21533e4 100644 --- a/src/stores/map-store.ts +++ b/src/stores/map-store.ts @@ -408,7 +408,9 @@ export abstract class MapStore extends ReduceStore> { for (let i = 0; i < moveList.length; i++) { let key = moveList[i]; let item = this.queuesHandler.Get(key); - stateMap.set(key, { ...item }); + if (item != null) { + stateMap.set(key, { ...item }); + } this.queuesHandler.Remove(key); } }); diff --git a/src/stores/reduce-store.ts b/src/stores/reduce-store.ts index b177d17..8b0f1fb 100644 --- a/src/stores/reduce-store.ts +++ b/src/stores/reduce-store.ts @@ -1,7 +1,7 @@ import * as Flux from "flux"; import { ReduceStore as FluxReduceStore } from "flux/utils"; import * as Immutable from "immutable"; -import { Dispatcher, DispatcherMessage, DispatcherBuilder } from "../dispatcher"; +import { Dispatcher, DispatcherMessage, DispatcherClass } from "../dispatcher"; export type ActionHandler = (action: TClass, state: TState) => TState | void; @@ -138,8 +138,8 @@ export abstract class ReduceStore extends FluxReduceStore