@fluid-topics/ft-wc-utils 1.1.2 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,6 @@
1
+ import { Optional, Provider } from "./generic-types";
1
2
  export declare const delay: (ms: number) => Promise<unknown>;
3
+ export declare function waitFor<T>(provider: Provider<Optional<T>>, interval?: number): Promise<T>;
2
4
  export declare function flatDeep<T>(arr: Array<T>, getChildren: (o: T) => Array<T>): Array<T>;
3
5
  export declare function dateReviver(...dateKeys: string[]): (key: string, value: any) => any;
4
6
  export declare function parseDate(value: string): Date;
package/build/helpers.js CHANGED
@@ -1,4 +1,12 @@
1
1
  export const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
2
+ export async function waitFor(provider, interval = 5) {
3
+ let value = provider();
4
+ while (value == null) {
5
+ await delay(interval);
6
+ value = provider();
7
+ }
8
+ return value;
9
+ }
2
10
  export function flatDeep(arr, getChildren) {
3
11
  return arr.flatMap(o => [o, ...flatDeep(getChildren(o), getChildren)]);
4
12
  }
package/build/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import "./silent-define";
2
2
  export declare const isSafari: boolean;
3
3
  export * from "./CacheRegistry";
4
4
  export * from "./CancelablePromise";
5
+ export * from "./conditional-visibility";
5
6
  export * from "./Debouncer";
6
7
  export * from "./decorators";
7
8
  export * from "./designSystemVariables";
package/build/index.js CHANGED
@@ -4,6 +4,7 @@ export const isSafari = (navigator.vendor && !!navigator.vendor.match(/apple/i))
4
4
  || ((_c = (_b = (_a = window.safari) === null || _a === void 0 ? void 0 : _a.pushNotification) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _c !== void 0 ? _c : "") === "[object SafariRemoteNotification]";
5
5
  export * from "./CacheRegistry";
6
6
  export * from "./CancelablePromise";
7
+ export * from "./conditional-visibility";
7
8
  export * from "./Debouncer";
8
9
  export * from "./decorators";
9
10
  export * from "./designSystemVariables";
@@ -0,0 +1,9 @@
1
+ import { Optional } from "../generic-types";
2
+ export interface FtCommand {
3
+ type: string;
4
+ }
5
+ export declare class FtCommandQueue {
6
+ private stack;
7
+ add(command: FtCommand, unique?: boolean): void;
8
+ consume<T extends FtCommand>(type: string): Optional<T>;
9
+ }
@@ -0,0 +1,18 @@
1
+ export class FtCommandQueue {
2
+ constructor() {
3
+ this.stack = [];
4
+ }
5
+ add(command, unique = false) {
6
+ if (unique) {
7
+ this.stack = this.stack.filter(c => c.type !== command.type);
8
+ }
9
+ this.stack.push(command);
10
+ }
11
+ consume(type) {
12
+ const maybeCommand = this.stack.find(c => c.type === type);
13
+ if (maybeCommand) {
14
+ this.stack = this.stack.filter(c => c !== maybeCommand);
15
+ }
16
+ return maybeCommand;
17
+ }
18
+ }
@@ -1,5 +1,6 @@
1
1
  import { Action, AnyAction, CaseReducerActions, Dispatch, Observable, Reducer, Slice, SliceCaseReducers, Store, Unsubscribe } from "@reduxjs/toolkit";
2
2
  import { DefaultStateReducer, FtCreateReduxStoreOptions, FtReduxStoreActions } from "./models";
3
+ import { FtCommandQueue } from "./FtCommandQueue";
3
4
  declare global {
4
5
  interface Window {
5
6
  ftReduxStores: Record<string, Store<any, any>>;
@@ -11,7 +12,8 @@ export declare class FtReduxStore<State = any, CR extends SliceCaseReducers<Stat
11
12
  readonly isFtReduxStore = true;
12
13
  static get<State = any, CR extends SliceCaseReducers<State> = SliceCaseReducers<State>, A extends Action = AnyAction>(name: string): FtReduxStore<State, CR, A> | undefined;
13
14
  static get<State = any, CR extends SliceCaseReducers<State> = SliceCaseReducers<State>, A extends Action = AnyAction>(options: FtCreateReduxStoreOptions<State, CR>): FtReduxStore<State, CR, A>;
14
- eventBus: EventTarget;
15
+ readonly eventBus: EventTarget;
16
+ readonly commands: FtCommandQueue;
15
17
  private constructor();
16
18
  clear(): void;
17
19
  setState(state: Partial<State>): void;
@@ -1,5 +1,6 @@
1
1
  import { configureStore, createSlice } from "@reduxjs/toolkit";
2
2
  import { isFtReduxStore } from "./models";
3
+ import { FtCommandQueue } from "./FtCommandQueue";
3
4
  if (!window.ftReduxStores) {
4
5
  window.ftReduxStores = {};
5
6
  }
@@ -39,6 +40,7 @@ export class FtReduxStore {
39
40
  this.reduxStore = reduxStore;
40
41
  this.isFtReduxStore = true;
41
42
  this.eventBus = document.createElement("event-bus");
43
+ this.commands = new FtCommandQueue();
42
44
  // Add proxy to automatically dispatch changes
43
45
  this.actions = new Proxy(this.reduxSlice.actions, {
44
46
  get: (target, p, receiver) => {
@@ -1,4 +1,5 @@
1
+ export * from "./decorators";
2
+ export * from "./FtCommandQueue";
1
3
  export * from "./FtLitElementRedux";
2
4
  export * from "./FtReduxStore";
3
- export * from "./decorators";
4
5
  export * from "./models";
@@ -1,4 +1,5 @@
1
+ export * from "./decorators";
2
+ export * from "./FtCommandQueue";
1
3
  export * from "./FtLitElementRedux";
2
4
  export * from "./FtReduxStore";
3
- export * from "./decorators";
4
5
  export * from "./models";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-topics/ft-wc-utils",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "Internal web components tools",
5
5
  "author": "Fluid Topics <devtopics@antidot.net>",
6
6
  "license": "ISC",
@@ -21,5 +21,5 @@
21
21
  "lit": "3.1.0",
22
22
  "mark.js": "8.11.1"
23
23
  },
24
- "gitHead": "53ce99f657872582bca43cbb7ad691b239b22823"
24
+ "gitHead": "b13ddd3359734158be660854f9ffe5fc5880c430"
25
25
  }