Simple yet powerful application class for a browser.
import app from 'uc-app';
app.init({ container: 'body' }, () => {
// here is your app is ready
// this will start the router
app.start();
});
You can use any API adapter.
app.setAPI(adapter);
The adapter should complain interface:
- call() - makes the api call.
- app() - gives your adapter access to the app instance.
- host — string, is the full api host name.
The app will add following methods to your adapter:
- log(level, ...args) — to log.
- emit(event, ...args) — to emit events.
app.router
For more info go to uc-router
Adds all the routes
to the router.
Navigates to the url
. Alias to router.go
.
For more info on following methods go to uc-dom
- addClass
- removeClass
- toggleClass
- replaceClass
- appendTo
- prependTo
- insertBefore
- insertAfter
- find
- attr
Adds the event handler
to the event
. You can use context
to set this
context for the handler. Returns the class instance so you can chain the calls.
Same as the above but fires only once.
Removes the event handler
to the event
. You should pass the context
if you subscribed to the event with context. Returns the class instance so you can chain the calls.
Emits the event
Logs all args
into console if level
is smaller than logLevel
property of the class.
- logLevel - number, defines the maximum log level to be printed out
- logName - string, if defined will be prepended to every log line
const LOG_LEVEL = {
NONE: 0,
ALERT: 1,
CRITICAL: 2,
ERROR: 3,
WARNING: 4,
NOTICE: 5,
INFO: 6,
DEBUG: 7,
ALL: 255
}
app.storage
— JSON local storage uc-storage
app.cookie
— access to the cookies uc-cookies
License MIT
© velocityzen