-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(stream): introduce concept of render strategies
* `DefaultRenderStrategy` * `ThrottleRenderStrategy` * `DebounceRenderStrategy`
- Loading branch information
1 parent
ebe638f
commit d413113
Showing
2 changed files
with
127 additions
and
8 deletions.
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
export interface RenderStrategy { | ||
type: 'default' | 'viewport' | 'throttle' | 'debounce'; | ||
} | ||
|
||
export interface DefaultRenderStategy extends RenderStrategy { | ||
type: 'default'; | ||
} | ||
|
||
export interface ViewportRenderStrategy extends RenderStrategy { | ||
type: 'viewport'; | ||
rootMargin?: string; | ||
threshold?: number | number[]; | ||
} | ||
|
||
export interface ThrottleRenderStrategy extends RenderStrategy { | ||
type: 'throttle'; | ||
throttleInMs: number; | ||
} | ||
|
||
export interface DebounceRenderStrategy extends RenderStrategy { | ||
type: 'debounce'; | ||
debounceInMs: number; | ||
} | ||
|
||
export type RenderStrategies = DefaultRenderStategy | ViewportRenderStrategy | ThrottleRenderStrategy; | ||
|
||
export function isDefaultRenderStrategy(strategy: RenderStrategy): strategy is DefaultRenderStategy { | ||
return strategy.type === 'default'; | ||
} | ||
|
||
export function isViewportRenderStrategy(strategy: RenderStrategy): strategy is ViewportRenderStrategy { | ||
return strategy.type === 'viewport'; | ||
} | ||
|
||
export function isThrottleRenderStrategy(strategy: RenderStrategy): strategy is ThrottleRenderStrategy { | ||
return strategy.type === 'throttle'; | ||
} | ||
|
||
export function isDebounceRenderStrategy(strategy: RenderStrategy): strategy is DebounceRenderStrategy { | ||
return strategy.type === 'debounce'; | ||
} |
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