@rekajs/core
The core package of Reka.
API
Reka
Classtsximport { Reka } from '@rekajs/core';import * as t from '@rekajs/types';import confetti from 'canvas-confetti';import { Header } from './path-to-header-component.tsx';const reka = Reka.create({externals: {states: {myGlobalVariable: 0,},functions: (reka) => ({getGlobalVariable: () => {return reka.getExternalState('myGlobalVariable');},confetti: () => {return confetti();},}),components: [t.externalComponent({name: 'MyReactHeader',render: (props) => {return <Header {...props} />;},}),],},});
- 
create(opts?:
RekaOpts):RekaCreate a new Reka instance
 - 
id:
string - 
frames:
Array<Frame>A list of RekaComponent instances
 - 
state:
StateThe primary State data structure. Changes to the State will cause all Frames to recompute their output View
 - 
loaded:
boolean - 
externals:
Object - 
changes:
Array<any> - 
volatile:
Object - 
setHistoryManager(manager:
HistoryManager):void - 
canUndo():
boolean - 
canRedo():
boolean - 
undo():
void - 
redo():
void - 
getCustomKind(name:
string):CustomKindDefinition - 
getExternalState(key:
string):any - 
getVolatileState(key:
string):any - 
setVolatileState<V>(key:
string, value:V):V - 
updateVolatileState:
Function@deprecated - Use setVolatileState()
 - 
updateExternalState(key:
string, value:any):void - 
program:
ProgramGet the Program AST node from State. Shorthand for state.program
 - 
components:
ObjectAll components that exists in the instance. Includes RekaComponents in the Program AST and ExternalComponents that was passed to the instance in the constructor.
 - 
load(state:
State, opts?:RekaLoadOpts):voidLoad a new State data type
 - 
sync(evaluateImmediately?:
boolean):Promise<Array>Sync changes made to the State to all active Frames. You usually do not need to call this manually.
 - 
change(mutator:
Function, opts?:RekaChangeOpts):Promise | undefinedPerform a mutation to the State
tsxreka.change(() => {reka.components.push(t.rekaComponent(...))}) - 
createFrame(opts:
FrameOpts, cb?:Function):FrameCreate a new Frame instance
 - 
removeFrame(frame:
Frame):voidRemove an existing Frame instance
 - 
getFrame(id:
string):Frame | undefinedGet a Frame instance by its id
 - 
getExtension<D extends
ExtensionDefinition>(definition:D):Extension<D>Get an Extension's state from its definition
 - 
getNodeFromId<T extends
Type>(id:string, expectedType?:TypeConstructor<T>):TGet an AST node by its id from the State
 - 
getParentNode<T extends
Type>(node:Type, expectedParentType?:TypeConstructor<T>):T | nullGet the nearest parent Node of a given AST node in the State.
tsxconst state = t.state({program: t.program({components: [t.rekaComponent({name: "App"...})]})})reka.load(state);const appComponent = state.program.components[0];console.log(reka.getParentNode(appComponent) === state.program); // true - 
getNodeLocation(node:
Type):ObjectGet the nearest parent Node and its relative path of a given AST node in the State.
tsxconst state = t.state({program: t.program({components: [t.rekaComponent({name: "App"...})]})})reka.load(state);const appComponent = state.program.components[0];const location = reka.getNodeLocation(appComponent);console.log(location.parent === state.program); // trueconsole.log(location.path) // ["components", 0] - 
getNodePathStr:
Function - 
listenToChangeset(subscriber:
Function):FunctionListen for changes and mutations made to the State
tsxreka.listenToChangeset((payload) => {console.log('node changed',payload.type,payload.newValue,payload.oldValue,payload.name);}); - 
subscribe<C>(collect:
Function, onCollect:Function, opts?:StateSubscriberOpts):FunctionSubscribe to changes made in a Reka instance
tsxreka.subscribe((state) => ({componentNames: state.program.components.map((component) => component.name),}),(collected) => {console.log('component names', collected.componentNames);}); - 
watch(cb:
Function):FunctionWatch changes made within a Reka instance
tsxreka.watch(() => {console.log('component names',state.program.components.map((component) => component.name));}); - 
createCachedQuery:
Function - 
dispose():
voidDispose instance, stops all future computations
 - 
toJSON():
State - 
getIdentifiablesAtNode:
Function - 
getIdentifiableFromIdentifier:
Function - 
getComponentSlots(component:
Component):Array | Map 
Frame
ClassCreates a Frame that computes an output View tree for a Component instance. You should not create this instance manually. Instead, use Reka.createFrame(...)
- 
id:
stringAn id to easily identify the Frame instance
 - 
sync:
booleanFrame only computes (and recomputes) its View when sync is set to true
 - 
opts:
FrameOpts - 
reka:
Reka - 
componentName:
string - 
component:
Component | null - 
view:
FrameViewGet the output View for the Frame
 - 
getViewFromId<T extends
View>(id:string, expectedType?:TypeConstructor<T>):TGet a View node by its id
 - 
getParentView<T extends
View>(view:View, expectedParentType?:TypeConstructor<T>):T | nullGet the parent View of the specified View node
 - 
enableSync():
voidEnable synching. Changes made to the State that affects the Frame's component will cause its View to be recomputed
 - 
disableSync():
voidDisable synching. Changes made to the State will not cause View to be recomputed
 - 
compute(evaluateImmediately?:
boolean, cb?:Function):Promise | undefinedCompute a View tree
 - 
setProps(props:
Record<string,any>):voidUpdate the props of the Component associated with the Frame
 - 
listenToChangeset:
FunctionListen for changes and mutations made to the Frame's output View
 - 
dispose():
void - 
getViewsForTpl(template:
Template):Array<View> 
Extension
Class- 
reka:
Reka - 
definition:
D - 
state:
ExtensionStateFromDefinition<D> - 
init():
any - 
dispose():
void - 
subscribe<C extends
Record>(collector:Function, subscriber:Function, opts?:StateSubscriberOpts):Function