redom-app

1.0.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i redom-app

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

7.1 kB

Total Files

4

Last publish

Collaborators

  • tareqk