What's this about
This repo exports three decorators (aka component enhancer functions, aka HOCs) providing component apis for avenger: queries
, commands
and loading
.
queries
Import the factory as
;
Create the decorator as
const queries = ;// where `allQueries` is a dictionary String -> Query, e.g.// {user: Query({ ... }), post: Query({ ... }) }
Use the decorator as
@Component { // `user` and `post` are passed as props as soon as they are ready (fetched). // `readyState` is passed as prop, containing meta-info for each declared query // and meta info for the whole component declaration. // examples: // `loading` for the whole decalration return thispropsreadyStateloading ? null : <div>Ready!</div> // `loading` for a single query return thispropsreadyStateuserloading ? null : <User user=thispropsuser /> // just render if we have something return thispropsuser ? <User user=thispropsuser /> }}
loading
In combination with @queries
, lets you conditionally render your component,
optionally in a layout including a "loader" component.
Import the factory as
;
Create the decorator as
const loading =
Use as
@@loadingComponent {}
loading configuration
loader
: default is "no loader", meaning that your component won't show any loading indicator. It will, nontheless, render only when "ready" (i.e. all the declared queries are resolved to a value).
wrapper
: default is <div />
. Not of much use if you don't have a loader.
Examples
const loading = ; // no loader const loading = ; const loading = ;
commands
Import the factory as
;
Create the decorator as
const queries = ;// where `allCommands` is a dictionary String -> Command, e.g.// { doSaveUserProfile: Command({ ... }) }
Use the decorator as
@Component { // `doSaveUserProfile` is passed as prop // example: return <div onClick= thisprops></div> }
real world usage
The examples below should work by themselves,
but in a real world project you might want to define and re-export a single queries
, commands
and loading
decorator,
to be used in component files.
For loading
, you might need different styles & layout, so we typically do something like:
; // or `fillAbsoluteLoading`, or `tinyLoading`, etc.