-
Notifications
You must be signed in to change notification settings - Fork 0
Jagwah
The Jagwah
class is used to create a new application instance, although you can create multiple instances within a single Browser context it's not the intended usage and has not been thoroughly tested.
You can create a new Jagwah instance using the Jagwah()
class.
const jagwah = new Jagwah(...);
When creating a new Jagwah instance you can pass in a Jagwah.options
object.
const jagwah = new Jagwah({
constants: { ... },
providers: [ ... ],
templates: [ ... ],
routes: [ ... ],
});
The constants
property is good for "global" information that you might need throughout your application, such as environment variables, urls and more. If the constants
property is used it should be an object with any shape.
const jagwah = new Jagwah({
constants: {
CDN_URL: 'https://cdn.jagwah.com/',
API_URL: 'https://api.jagwah.com/',
},
});
The providers
, templates
and routes
properties can be used to register arrays of Providers, Templates and Routes instead of using the individual methods (jagwah.Provider()
, jagwah.Template()
, jagwah.Route()
).
const jagwah = new Jagwah({
providers: [MyProvider, ...],
templates: [MyTemplate, ...],
routes: [MyRoute, ...],
});
An neat way to use the providers
, templates
and routes
properties is to use barrel files and import your modules all at once and then use the Object.values()
method.
import * as providers from './providers';
const jagwah = new Jagwah({
providers: Object.values(providers),
...
});
The start()
method is used to initialize a Jagwah application, it takes one argument (Jagwah.start.options
) which has optional before
and after
properties. Those properties accept an array of middleware-like classes, you can use dependency injection and run tasks before the first update
occurs.
The example below has a single before
handler injects an AccountProvider
to check the sign-in status before the first render. Things that occur within the before
handler should be fast because they'll prevent the initial render.
export class BeforeStartCheckAuth {
constructor(
@Inject('$account') private $account: providers.AccountProvider,
) {}
async task() {
await this.$account.signCheck();
}
}
jagwah.start({
before: [BeforeStartCheckAuth],
after: []
});
The classes should use dependency injection during construction and expose a task()
method which will be called by Jagwah.
During runtime Jagwah will emit events via the radio
property which works as a simple event emitter.
Called after jagwah.start()
methods completes.
Called after jagwah.Template()
methods completes, if the Template was named it will return the name, otherwise it will return "anonymous"
.
Called after jagwah.Provider()
methods completes, it will return the name of the Provider.
Called after jagwah.Route()
methods completes, it will return the path of the Route.
Called after jagwah.update()
methods completes.
Called before a route change occurs.
Called after a route change occurs.