Unchained UI
Views UI Component
Usage
;;; // ... init your app ... const views = routes: 'post' '/post(/:slug)' Post 'page' '/(:page)' Page ;
;
This component follows Unchained UI guidelines.
Constructor options:
- routes array, routes and views mapping. Each element is an array.
[<name>, <pattern>, <ViewClass> [, AuthenticatedViewClass]]
. IfAuthenticatedViewClass
is present, the views will show it instead of theViewClass
when app is authenticated. Check the uc-app for more info. - onChange — function, callback will be called when view is changed.
- el — HTMLElement, the views container. If ommited the
div.views
is created. - rootEl — HTMLElement, default
html
, top element to apply active view classes. - rootPath - string, root path
Methods
remove()
Removes the views.
View
The View
is a simple JavaScript class. The only requirements are:
- el – HTMLElement, the view element.
- name – string, the name of the view.
- state - method to receive the current state.
The View
can have the following methods.
willOpen
, didOpen
, willClose
, didClose
. Will- methods are asynchronous.
Example:
; const Page = { thisel = ;}Pageprototype = name: 'Page' { console; ; // here we can return an error: cb(new Error()); // or replace the history state: cb(null, '/newurl'); } { console; ; } { console; } { console; ; } { console; }
License MIT
© velocityzen