Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(🎣 BlueRainHook Component): New component to handler async hook l…
…ogic Processes the async hook logic and returns final value as a param in render prop function
- Loading branch information
Showing
3 changed files
with
48 additions
and
0 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
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,45 @@ | ||
import { BlueRain } from '../../BlueRain'; | ||
import { BlueRainConsumer } from '../../Context'; | ||
import Loadable from 'react-loadable'; | ||
import React from 'react'; | ||
|
||
// const example = () => ( | ||
// <BlueRainHook hook="bluerain.event" value={5} args={{ foo: 'bar' }}> | ||
// {(value) => console.log(value)} | ||
// </BlueRainHook> | ||
// ); | ||
|
||
export interface BlueRainHookProperties<T = any> { | ||
hook: string; | ||
value: T; | ||
args?: { [key: string]: any }; | ||
children: ((value: any) => React.ReactNode); | ||
} | ||
|
||
export class BlueRainHook extends React.PureComponent<BlueRainHookProperties> { | ||
|
||
public static defaultProps = { | ||
args: {} | ||
}; | ||
|
||
render() { | ||
|
||
const { hook, value, args, children } = this.props; | ||
|
||
return ( | ||
<BlueRainConsumer children={(BR: BlueRain) => { | ||
|
||
const AsyncBlueRainHook = Loadable({ | ||
loader: () => BR.Hooks.run(hook, value, args), | ||
loading: () => <BR.Components.Text>Loading</BR.Components.Text>, | ||
render(loadedValue: any) { | ||
return children(loadedValue); | ||
} | ||
}); | ||
|
||
return <AsyncBlueRainHook />; | ||
|
||
}} /> | ||
); | ||
} | ||
} |
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 @@ | ||
export * from './BlueRainHook'; |