Setup
Rebone will need you to manually import your components (views, collections, models). In your entry point, add the following:
// Load reducers; // Load component filesconst requireAll = { r; };;;; ;;
You may need to update the location of your component folder since the default is set to ./components
Creating a template
The system is using mustache as a templating engine, for more information please have a look at https://mustache.github.io/
Note on
data-view='Posts'
anddata-collection='Posts'
All views should extend ComponentView which connects to the global redux store and registers the view to receive store updates for conditional rendering and prop validation:
;;;;;; { superoptions; // Initialize props thispropTypes = optionspropTypes; thisprops = optionsprops; // Assign each view a unique ID to coordinate reactive view rendering based on the redux state. thisuuid = ; // Subscribe to ALL store update events. For now, the views will handle filtering the actions to decide // if they want to render or not based on what actions have been dispatched. store; // If the view is instantiated sometime after the app has loaded then the state changes may be finished // so check if we need to go ahead with the runOnce. this; // Validate propTypes thispropTypes && this; } /** * Checks if any actions were defined that need to be called via dispatch and wraps them. */ { if thismapDispatchToProps thisprops = ...thisprops ... ; // Add mapped dispatch functions to propTypes with function as type thispropTypes = thispropTypes ? thispropTypes : {}; Object; // Check the propTypes again since we've just added new ones this; }; /** * Validate prop types if props are present. */ { Object; } /** * Returns an instance of the store. * @type */ store = store; /** * Returns access to dispatch for thunks (redux actions as functions) and regular actions (objects with type property). * @type */ dispatch = storedispatch; /** * Run onAppReady once if defined on the subclass. * This ensures that all collections and views have been loaded * and all reducers have set their initial states in the store. */ { const state = store; if !thisloaded && stateapp && stateapploaded this; // Check if there is view-specific logic to execute when the store is fully loaded // Define onAppReady in the view to access this callback if typeof thisonAppReady === 'function' this; thisloaded = true; } /** * Returns the jQuery element of the rendered view. * Useful for pre-rendering a view to include as part of the render to another view. * @param * @param * @return */ { const $el = viewName ...options ; return $el; } /** * Will execute each time the state is updated in the store. */ { this; if thisuuid const app: alertedListeners = store; // Check if the current view needs to be notified about the store update if alertedListeners store; // Execute view-specific logic (if provided) before calling render // Define onViewNotified in the view to access this callback if typeof thisonViewNotified === 'function' this; this; // Check if there is view-specific logic to execute on ANY store update // Define onStoreUpdated in the view to access this callback if typeof thisonStoreUpdated === 'function' this; }; /** * Sets which element in the DOM to be used as the Underscore template. * @param */ { thistemplate = _; }; /** * Gets an instance of a template. This usefull when you have more than just one template. * @param */ _; /** * Export underscore instance. */ _ = _;
Example View:
;; ; { super ...options events: 'click .post-button': 'buttonClicked' ; } { this; thisprops; } { const modelId = thisdata'post-id'; let model = thiscollection; model; } { const filter: currentFilter = thisstore; const posts = thiscollection; this; } /** * Define functions which need to be wrapped with dispatch. * @type */ mapDispatchToProps = fetchCollection ; appviewsPosts = Posts;