Skip to content

Commit

Permalink
feat: Watcher's single mode now relay on LiveSelector
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Works committed Sep 6, 2019
1 parent 163a195 commit a05cf3b
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 8 deletions.
17 changes: 17 additions & 0 deletions api-documents/kit.watcher.dismisssinglemodewarning.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@holoflows/kit](./kit.md) &gt; [Watcher](./kit.watcher.md) &gt; [dismissSingleModeWarning](./kit.watcher.dismisssinglemodewarning.md)

## Watcher.dismissSingleModeWarning() method

Dismiss the warning that let you enable single mode but the warning is false positive.

<b>Signature:</b>

```typescript
dismissSingleModeWarning(): this;
```
<b>Returns:</b>

`this`

4 changes: 4 additions & 0 deletions api-documents/kit.watcher.enablebatchmode.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

## Watcher.enableBatchMode() method

> Warning: This API is now obsolete.
>
>
Dismiss the warning that let you enable single mode but the warning is false positive.

<b>Signature:</b>
Expand Down
5 changes: 5 additions & 0 deletions api-documents/kit.watcher.enablesinglemode.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

## Watcher.enableSingleMode() method

> Warning: This API is now obsolete.
>
> Use LiveSelector.enableSingleMode()
>
Enable single mode.

<b>Signature:</b>
Expand Down
1 change: 1 addition & 0 deletions api-documents/kit.watcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export declare abstract class Watcher<T, Before extends Element, After extends E
| [addListener(event, fn)](./kit.watcher.addlistener_2.md) | | |
| [addListener(event, fn)](./kit.watcher.addlistener_3.md) | | |
| [assignKeys(keyAssigner)](./kit.watcher.assignkeys.md) | | To help identify same nodes in different iteration, you need to implement a map function that map <code>node</code> to <code>key</code>If the key is changed, the same node will call through <code>forEachRemove</code> then <code>forEach</code> |
| [dismissSingleModeWarning()](./kit.watcher.dismisssinglemodewarning.md) | | Dismiss the warning that let you enable single mode but the warning is false positive. |
| [emit(event, data)](./kit.watcher.emit.md) | | |
| [emit(event, data)](./kit.watcher.emit_1.md) | | |
| [emit(event, data)](./kit.watcher.emit_2.md) | | |
Expand Down
2 changes: 1 addition & 1 deletion api-documents/kit.watcher.singlemode.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ Is the single mode is on.
<b>Signature:</b>

```typescript
protected singleMode: boolean;
protected readonly singleMode: boolean;
```
5 changes: 4 additions & 1 deletion doc/holoflows-kit.api.report.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ export abstract class Watcher<T, Before extends Element, After extends Element,
// (undocumented)
addListener(event: 'onAdd', fn: EventCallback<OnAddOrRemoveEvent<T>>): this;
assignKeys<Q = unknown>(keyAssigner: (node: T, index: number, arr: readonly T[]) => Q): this;
dismissSingleModeWarning(): this;
protected domProxyOption: Partial<DomProxyOptions<Before, After>>;
// (undocumented)
protected emit(event: 'onIteration', data: OnIterationEvent<T>): void;
Expand All @@ -248,7 +249,9 @@ export abstract class Watcher<T, Before extends Element, After extends Element,
protected emit(event: 'onRemove', data: OnAddOrRemoveEvent<T>): void;
// (undocumented)
protected emit(event: 'onAdd', data: OnAddOrRemoveEvent<T>): void;
// @deprecated
enableBatchMode(): this;
// @deprecated
abstract enableSingleMode(): Watcher<T, Before, After, true>;
// (undocumented)
protected _enableSingleMode(): this;
Expand Down Expand Up @@ -280,7 +283,7 @@ export abstract class Watcher<T, Before extends Element, After extends Element,
protected scheduleWatcherCheck: () => void;
setComparer<Q = unknown>(keyComparer?: (a: Q, b: Q) => boolean, valueComparer?: (a: T, b: T) => boolean): this;
setDomProxyOption(option: Partial<DomProxyOptions<Before, After>>): this;
protected singleMode: boolean;
protected readonly singleMode: boolean;
protected singleModeCallback?: useForeachReturns<T>;
protected singleModeHasLastValue: boolean;
protected singleModeLastValue?: T;
Expand Down
2 changes: 1 addition & 1 deletion src/DOM/LiveSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class LiveSelector<T, SingleMode extends boolean = false> {
/**
* Is this LiveSelector run in the SingleMode
*/
public isSingleMode = false
private isSingleMode = false
/**
* Enable single mode. Only 1 result will be emitted.
*/
Expand Down
24 changes: 19 additions & 5 deletions src/DOM/Watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export abstract class Watcher<T, Before extends Element, After extends Element,
protected readonly liveSelector: LiveSelector<T, SingleMode>
constructor(liveSelector: LiveSelector<T, SingleMode>) {
this.liveSelector = liveSelector.clone()
if (this.liveSelector.isSingleMode) this.enableSingleMode()
}
//#region How to start and stop the watcher
/** Let the watcher start to watching */
Expand Down Expand Up @@ -367,6 +366,8 @@ export abstract class Watcher<T, Before extends Element, After extends Element,
/**
* Enable single mode.
*
* @deprecated Use LiveSelector.enableSingleMode()
*
* @privateRemarks
* Subclass need to implement it to get the correct type.
* Example to subclass implementor:
Expand All @@ -384,15 +385,20 @@ export abstract class Watcher<T, Before extends Element, After extends Element,
* Every subclass should call this.
*/
protected _enableSingleMode() {
console.warn(
'You should call this method on LiveSelector instead of a Watcher. Watcher.enableSingleMode is deprecated.',
)
this._warning_single_mode.ignored = true
this.singleMode = true
this.liveSelector.enableSingleMode()
return this
}
/**
* Is the single mode is on.
*/
protected singleMode = false
protected get singleMode(): boolean {
// @ts-ignore
return this.liveSelector.isSingleMode
}
/** Last iteration value for single mode */
protected singleModeLastValue?: T
/** Does it has a last iteration value in single mode? */
Expand Down Expand Up @@ -661,15 +667,23 @@ export abstract class Watcher<T, Before extends Element, After extends Element,
console.warn(
`Your watcher seems like only watching 1 node.
If you can make sure there is only 1 node to watch, call \`.enableSingleMode()\` on the watcher.
Or to ignore this message, call \`.enableBatchMode()\` on the watcher.\n`,
Or to ignore this message, call \`.dismissSingleModeWarning()\` on the watcher.\n`,
stack,
)
},
})
/**
* Dismiss the warning that let you enable single mode but the warning is false positive.
* {@inheritdoc Watcher.dismissSingleModeWarning}
* @deprecated
*/
public enableBatchMode(): this {
console.warn('This method is deprecated. Use dismissSingleModeWarning() instead.')
return this.dismissSingleModeWarning()
}
/**
* Dismiss the warning that let you enable single mode but the warning is false positive.
*/
public dismissSingleModeWarning(): this {
this._warning_single_mode.ignored = true
return this
}
Expand Down

0 comments on commit a05cf3b

Please sign in to comment.