Skip to content

Commit 8b0a43c

Browse files
committed
chore: init applyfiltersAsync
1 parent 8b5a248 commit 8b0a43c

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

src/apphook.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { FilterCommand, TriggerCommand } from './commands';
1010
import { IRule } from './rules';
1111
import { IFilterAction, ITriggerAction } from './actions';
1212
import { IListener, ITrigger, ListenerType as ListenerType, IFilter } from './listeners';
13-
import { AddTriggerEvent, DoTriggerEvent, UseFiltersEvent, AddFilterEvent } from './hook_events';
13+
import { AddTriggerEvent, DoTriggerEvent, WhenApplyFiltersEvent, AddFilterEvent } from './hook_events';
1414

1515
interface IListenersMap {
1616
[listenerType: string]: {
@@ -48,10 +48,10 @@ export class AppHook {
4848
* Use for inner self-inspection,
4949
* the event action that can be bound to useFilters
5050
*
51-
* @type {UseFiltersEvent}
51+
* @type {WhenApplyFiltersEvent}
5252
* @memberof AppHook
5353
*/
54-
_onUseFilters: UseFiltersEvent | undefined;
54+
_whenApplyFilters: WhenApplyFiltersEvent | undefined;
5555

5656
/**
5757
* When AddFilter triggered, the inner event.
@@ -61,6 +61,11 @@ export class AppHook {
6161
*/
6262
_onAddFilter: AddFilterEvent | undefined;
6363

64+
// async applyFiltersAsync<T>(hook: string, defaultValue: any, hookState?: any): Promise<T> {
65+
66+
// return await ;
67+
// }
68+
6469
/**
6570
*
6671
* Add Trigger
@@ -135,11 +140,11 @@ export class AppHook {
135140
/**
136141
* binding the method will be called when applyFilters
137142
*
138-
* @param {UseFiltersEvent} bind
143+
* @param {WhenApplyFiltersEvent} bind
139144
* @memberof AppHook
140145
*/
141-
bindUseFilters(bind: UseFiltersEvent) {
142-
this._onUseFilters = bind;
146+
bindUseFilters(bind: WhenApplyFiltersEvent) {
147+
this._whenApplyFilters = bind;
143148
}
144149

145150
/**
@@ -371,8 +376,8 @@ export class AppHook {
371376
* @memberof AppHook
372377
*/
373378
applyFilters(hook: string, defaultValue: any, hookState?: any): any {
374-
if (this._onUseFilters != null) {
375-
this._onUseFilters(hook, defaultValue, hookState);
379+
if (this._whenApplyFilters != null) {
380+
this._whenApplyFilters(hook, defaultValue, hookState);
376381
}
377382

378383
const filterMap = this._listeners[ListenerType.Filter];

src/hook_events.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@ export type AddFilterEvent = (hook: string,
2525

2626
export type DoTriggerEvent = (hook: string, hookState?: any) => void;
2727

28-
export type UseFiltersEvent = (hook: string, defaultValue: any, hookState?: any) => void;
28+
/**
29+
* the event that will be triggered when use applyFilters
30+
*/
31+
export type WhenApplyFiltersEvent = (hook: string, defaultValue: any, hookState?: any) => void;

tests/apphook.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ describe('test appHook', () => {
5555
// true);
5656
// apphook.doTriggers('test_error_event', 321);
5757
});
58+
// it('should call trigger event ok (async)', async () => {
59+
// const apphook = new AppHook();
60+
// async filter
61+
// const filter1: IFilter = apphook.addFilterAsync('test',
62+
// defaultValue => (defaultValue + ' Filtered1'),
63+
// []);
64+
// expect(filter1.hook).toBe('test');
65+
// async action
66+
67+
// });
5868

5969
it('should call filter event ok', () => {
6070
const apphook = new AppHook();

0 commit comments

Comments
 (0)