-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(basics): add
useBasicsStream
for convenient usage
by default it will register all available basics stream closes #44
- Loading branch information
Showing
4 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './features' | ||
export * from './operators' | ||
export * from './use-basics-stream' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import * as ExportedStreams from './features' | ||
|
||
export interface UseBasicsStreamConfig { | ||
Init?: boolean | ||
Timer?: boolean | ||
} | ||
|
||
const defaultConfig: UseBasicsStreamConfig = { | ||
Init: true, | ||
Timer: true, | ||
} | ||
|
||
/** | ||
* Register all components as Bara stream | ||
*/ | ||
export function useBasicsStream(config?: UseBasicsStreamConfig) { | ||
const combinedConfig = { ...defaultConfig, ...config } | ||
for (const component in combinedConfig) { | ||
if ((combinedConfig as any)[component] === true) { | ||
const methodName = `use${component}Stream` | ||
if (methodName in ExportedStreams) { | ||
;(ExportedStreams as any)[methodName]() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { | ||
register, | ||
useAction, | ||
useCondition, | ||
useEvent, | ||
useStream, | ||
useTrigger, | ||
} from '@bara/core' | ||
|
||
import { useBasicsStream, useInit } from '../src' | ||
|
||
describe('basics/use-basics-stream tests', () => { | ||
it('not emit init when disable from useBasicsStream', done => { | ||
const handler = jest.fn() | ||
|
||
const app = register(() => { | ||
useBasicsStream({ Init: false }) | ||
useInit(handler) | ||
}) | ||
|
||
setTimeout(() => { | ||
expect(handler).not.toHaveBeenCalled() | ||
done() | ||
}, 100) | ||
}) | ||
}) |