Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
falsandtru committed Dec 31, 2020
1 parent 9e3814b commit 9c33af4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
10 changes: 5 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export namespace ChannelObject {
export class StoreChannel<K extends string, V extends StoreChannelObject<K>> {
constructor(name: string, config: StoreChannelConfig<K, V>);
readonly events: {
readonly load: Observer<[K] | [K, Extract<keyof V | '', string>] | [K, Extract<keyof V | '', string>, StoreChannelEventType], StoreChannelEvent<K, V>, void>;
readonly save: Observer<[K] | [K, Extract<keyof V | '', string>] | [K, Extract<keyof V | '', string>, StoreChannelEventType], StoreChannelEvent<K, V>, void>;
readonly loss: Observer<[K] | [K, Extract<keyof V | '', string>] | [K, Extract<keyof V | '', string>, StoreChannelEventType], StoreChannelEvent<K, V>, void>;
readonly load: Observer<[K, Extract<keyof V | '', string>, StoreChannelEventType], StoreChannelEvent<K, V>, void>;
readonly save: Observer<[K, Extract<keyof V | '', string>, StoreChannelEventType], StoreChannelEvent<K, V>, void>;
readonly loss: Observer<[K, Extract<keyof V | '', string>, StoreChannelEventType], StoreChannelEvent<K, V>, void>;
};
sync(keys: K[], timeout?: number): Promise<PromiseSettledResult<K>[]>;
link(key: K, age?: number): V;
Expand All @@ -35,7 +35,7 @@ export interface StoreChannelObject<K extends string> {
readonly [ChannelObject.id]: number;
readonly [ChannelObject.key]: K;
readonly [ChannelObject.date]: number;
readonly [ChannelObject.event]: Observer<[StorageChannelEventType] | [StorageChannelEventType, Extract<keyof this, string>], StorageChannelEvent<this>, void>;
readonly [ChannelObject.event]: Observer<[StorageChannelEventType, Extract<keyof this, string>], StorageChannelEvent<this>, void>;
}
export interface StoreChannelObjectMetaData<K extends string> {
readonly id: number;
Expand Down Expand Up @@ -73,7 +73,7 @@ export interface StorageChannelConfig<V extends StorageChannelObject> {
migrate?(link: V): void;
}
export interface StorageChannelObject {
readonly [ChannelObject.event]: Observer<[StorageChannelEventType] | [StorageChannelEventType, Extract<keyof this, string>], StorageChannelEvent<this>, void>;
readonly [ChannelObject.event]: Observer<[StorageChannelEventType, Extract<keyof this, string>], StorageChannelEvent<this>, void>;
}
export interface StorageChannelEvent<V> {
readonly type: StorageChannelEventType;
Expand Down
8 changes: 4 additions & 4 deletions src/layer/data/es/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ export abstract class EventStore<K extends string, V extends EventStore.Value> {
}
private readonly memory = new Observation<[] | [K] | [K, keyof V | ''] | [K, keyof V | '', string] | [K, keyof V | '', string, string], void, UnstoredEventRecord<K, V> | LoadedEventRecord<K, V> | SavedEventRecord<K, V>>();
public readonly events = Object.freeze({
load: new Observation<[K] | [K, Extract<keyof V | '', string>] | [K, Extract<keyof V | '', string>, EventStore.EventType], EventStore.Event<K, V>, void>(),
save: new Observation<[K] | [K, Extract<keyof V | '', string>] | [K, Extract<keyof V | '', string>, EventStore.EventType], EventStore.Event<K, V>, void>(),
loss: new Observation<[K] | [K, Extract<keyof V | '', string>] | [K, Extract<keyof V | '', string>, EventStore.EventType], EventStore.Event<K, V>, void>(),
load: new Observation<[K, Extract<keyof V | '', string>, EventStore.EventType], EventStore.Event<K, V>, void>(),
save: new Observation<[K, Extract<keyof V | '', string>, EventStore.EventType], EventStore.Event<K, V>, void>(),
loss: new Observation<[K, Extract<keyof V | '', string>, EventStore.EventType], EventStore.Event<K, V>, void>(),
clean: new Observation<[K], boolean, void>(),
});
private readonly events_ = Object.freeze({
memory: new Observation<[K] | [K, keyof V | ''] | [K, keyof V | '', string], UnstoredEventRecord<K, V> | LoadedEventRecord<K, V> | SavedEventRecord<K, V>, void>({ limit: Infinity }),
memory: new Observation<[K, keyof V | '', string], UnstoredEventRecord<K, V> | LoadedEventRecord<K, V> | SavedEventRecord<K, V>, void>({ limit: Infinity }),
});
private tx_: {
rw?: IDBTransaction;
Expand Down
10 changes: 5 additions & 5 deletions src/layer/domain/indexeddb/model/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ export class ChannelStore<K extends string, V extends StoreChannelObject<K>> {
};
})(), { ignore: { delete: true } });
public readonly events_ = Object.freeze({
load: new Observation<[K] | [K, keyof V | ''] | [K, keyof V | '', ChannelStore.EventType], ChannelStore.Event<K, V>, void>(),
save: new Observation<[K] | [K, keyof V | ''] | [K, keyof V | '', ChannelStore.EventType], ChannelStore.Event<K, V>, void>(),
load: new Observation<[K, keyof V | '', ChannelStore.EventType], ChannelStore.Event<K, V>, void>(),
save: new Observation<[K, keyof V | '', ChannelStore.EventType], ChannelStore.Event<K, V>, void>(),
clean: new Observation<[K], boolean, void>(),
});
public readonly events = Object.freeze({
load: new Observation<[K] | [K, Extract<keyof V | '', string>] | [K, Extract<keyof V | '', string>, ChannelStore.EventType], ChannelStore.Event<K, V>, void>({ limit: Infinity }),
save: new Observation<[K] | [K, Extract<keyof V | '', string>] | [K, Extract<keyof V | '', string>, ChannelStore.EventType], ChannelStore.Event<K, V>, void>({ limit: Infinity }),
loss: new Observation<[K] | [K, Extract<keyof V | '', string>] | [K, Extract<keyof V | '', string>, ChannelStore.EventType], ChannelStore.Event<K, V>, void>({ limit: Infinity }),
load: new Observation<[K, Extract<keyof V | '', string>, ChannelStore.EventType], ChannelStore.Event<K, V>, void>({ limit: Infinity }),
save: new Observation<[K, Extract<keyof V | '', string>, ChannelStore.EventType], ChannelStore.Event<K, V>, void>({ limit: Infinity }),
loss: new Observation<[K, Extract<keyof V | '', string>, ChannelStore.EventType], ChannelStore.Event<K, V>, void>({ limit: Infinity }),
});
public sync(keys: K[], timeout = Infinity): Promise<PromiseSettledResult<K>[]> {
const cancellation = new Cancellation();
Expand Down
2 changes: 1 addition & 1 deletion src/layer/domain/webstorage/service/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class StorageChannel<V extends StorageChannelObject> implements IStorageC
const source: V = {
...parse<V>(this.storage.getItem(this.name)),
[Schema.key]: this.name,
[Schema.event]: new Observation<[StorageChannelEventType] | [StorageChannelEventType, keyof V], StorageChannel.Event<V>, void>({ limit: Infinity }),
[Schema.event]: new Observation<[StorageChannelEventType, keyof V], StorageChannel.Event<V>, void>({ limit: Infinity }),
};
this.link_ = build<V>(source, factory, (attr, newValue, oldValue) => {
void this.storage.setItem(this.name, JSON.stringify(Object.keys(source).filter(isValidPropertyName).filter(isValidPropertyValue(source)).reduce((acc, attr) => {
Expand Down
4 changes: 2 additions & 2 deletions src/layer/infrastructure/indexeddb/model/event.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Observation, Observer } from 'spica/observer';

export const idbEventStream_ = new Observation<[string] | [string, IDBEventType], IDBEvent, void>({ limit: Infinity });
export const idbEventStream: Observer<[string] | [string, IDBEventType], IDBEvent, void> = idbEventStream_;
export const idbEventStream_ = new Observation<[string, IDBEventType], IDBEvent, void>({ limit: Infinity });
export const idbEventStream: Observer<[string, IDBEventType], IDBEvent, void> = idbEventStream_;

export const enum IDBEventType {
connect = 'connect',
Expand Down

0 comments on commit 9c33af4

Please sign in to comment.