1.0.0 • Published 4 years ago

redom-app v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

Redom Router

A simple Single Page Application Framework Built on the RE:DOM library.

installation

 npm install redom-app

Getting Started

In your application entry point, add

import {App} from 'redom-app'

/*some code*/
const app = new App().routes({
    home: Home,
    default: Home,
}).start()

where default is the default view if no other views are specified and each key:value pair is the name of the route and the View class.

Each view looks like this

class Home {
    constructor() {
        this.el = el('div', [//needs to be the property this.el
            el('h1','home'),
            // Rest of your elements, just like in RE:DOM
        ]);
    }

    update(params) {
        //Do whatever you want with the parameters
    }
}

Redirection

import {goto} from 'redom-app'
//some code here

goto('view-name',['param1','param2'])

Middleware

class SomeMiddleware {
    constructor() {

    }
    //this is what the middleware method looks like
    exec(currentView, nextView, params) {
        if(//some condition here){
            return 'other-view'// the view to redirect to. Stops execution of other middlewares
        }else{
            return nextView
        }
       
    }

}
/*in your entry point*/
const app = new App().routes({
    home: Home,
    default: Home,
}).middlewares([new SomeMiddleware()]).start()

More Examples

Examples can be found in here