Fast-Forward-Framework
A simple Event Driven Framework for React Native developers
"Focus on your app logic and your cool UI ... we manage the rest"
Fast-Forward provides a convenient way to communicate between all the elements (components, providers, stores, utils, ...etc.) that compose your app and prevents Spaghetti code.
Fast-Forward is lightweight, you can use it on an existing project without breaking changes or in a brand new one.
Fast-Forward also offer a way to monitor what's happening in your app, via :
- Clear console logs
- A tracking system that stores every F-F communication. You can dump the data so it can be analyzed/visualized with an external tool (to be released)
- An integrated
console.timeStamp()
system to efficiently debug/analyze in chrome
Install
In your React Native project folder
npm install fast-forward-framework --save
Usage
Initialize the Framework
...//during your app start up{superpropsff_Core; //see API section for options detail}
Create a set of trigger constants
moduleexports = //Providers triggers FETCH_DATA:'fetchData' //Components triggers ON_DATA_LOADED:'ondataloaded' ON_DATA_LOADING_PROGRESS:'ondataloadingProgress'
Create a Fast-Forward compatible RN component
; { superprops; thisstate = data:"" } { this; this; // register an handler with a HIGH priority } { this return ff_Block:true; // stop propagation } { return //Your rendering }
using SimpleView component
;...//in the JSX<SimpleView FFId="functionalView#1"></SimpleView>
Create a Fast-Forward compatible custom object
;; const __NAME="mySimpProvider"; { super__NAME; this; } { this; } { this } moduleexports = ;
API
Core init
ff_Core
Options :
- ###### maxLoglvl (default : OFF) The maximun log level displayed in the console. Can be any of the following values:
ff_Constants.LOG_ERROR
, ff_Constants.LOG_WARN
, ff_Constants.LOG_INFO
, ff_Constants.LOG_OFF
Example :
ff_Core;
- ###### verbose (default : OFF) Gives you some extra logs. Can be any of the following values:
ff_Constants.VERBOSE_LOG_ON
, ff_Constants.VERBOSE_LOG_OFF
Example :
ff_Core;
-
###### tracking (default: DISABLE) Enable the event tracking system. Can be any of the following values:
ff_Constants.TRACKING_ENABLE
,ff_Constants.TRACKING_DISABLE
-
###### timeStamp (default: DISABLE) Enable console timestamps. Can be any of the following values:
ff_Constants.TIMESTAMP_ENABLE
,ff_Constants.TIMESTAMP_DISABLE
Core Toggle Tracking system
ff_Core;
Activate or deActivate the tracking. Can use any of the following values:
ff_Constants.TRACKING_ENABLE
, ff_Constants.TRACKING_DISABLE
Core Reset Tracking map
ff_Core;
Clear the stored data.
Core Dump Tracking map
ff_Core;
return all the tracked data
Core Toggle TimeStamp
ff_Core;
Activate or deActivate the tracking. Can use any of the following values:
ff_Constants.TIMESTAMP_ENABLE
, ff_Constants.TIMESTAMP_DISABLE
Core Register
ff_Core;
Manually add a listener for a given topic (or trigger or event or whatever you want to call it)
- id : A unique string that represents the object that is registering
- topic : A string which represents a Trigger (see Create a set of trigger constants)
- callback : A function, that will act as a handler
- priorityLvl : A number which defined the priority lvl of the callback. The lower the priority, the sooner the callback back will be called.
Core Unregister an component for a topic
ff_Core;
Remove the listener of a component for a specific topic
- topic : The topic we want to stop listening for
- receiver : The component/class that registered for the topic
Core Unregister All topics
ff_Core;
Remove the listener of a component for a specific topic
- receiver : The component / class that registered for topics
Core Dispatch
ff_Core;
Send an topic/event/trigger/...etc. thru the framework
- id : The id of the component / class that is emitting
- topic : The topic that is going to be broadcasted
- data : The data to be carried to the handlers
Notice
You can use Fast-Forward without using the ff_Dispatcher nor the ff_Component classes but they provide a good abstraction to the Framework. For instance, the ff_Component automaticcaly unregister all the listener when the component is unmounted.
In order to properly use the trackin system each dispatcher (ff_Component or ff_Dispatcher) should provide an ID:
- ff_Component : thru the
props.FFID
- ff_Dispatcher : thru the super() method
; const __NAME="mySimpProvider"; { super__NAME; }
An handler can stop the propagation of the event by return a specific property : ff_Block
set to TRUE
this; { this return ff_Block:true; }
TODO
- Release a Sample app
- Release the track map visualization tool
Contributors
- Guillaume Nachury ( @__Guillaume )