Skip to content

TypeScript

Brod edited this page Jul 14, 2018 · 6 revisions

Jagwah provides a few Typescript specific things such as Decorators and Modules / Interfaces.

Decorators

@Provider

The @Provider decorator can be used to set the static $provider property used by Providers.

import { Provider } from 'jagwah';
​
@Provider('$notif')
export class NotificationProvider {
  constructor() {}
}

@Template

The @Template decorator can be used to set the static $template and optionally the $selector property used by Templates.

import { Template } from 'jagwah';
​
@Template('notifications', '#notifications')
export class NotificationsTemplate {
  constructor() {}
}

@Templates

The @Templates decorator can be used to set the static $templates property used by Routes.

import { Templates } from 'jagwah';
​
@Templates([AccountTemplate])
export class AccountRoute {
  constructor() {}
}

@Inject

The @Inject decorator can be used to set and append the static $inject property used by Providers, Templates, Routes, Middleware and more.

import { Provider } from 'jagwah';
​
export class AccountProvider {
  constructor(
    @Inject('$notif') private $notif: NotificationProvider
  ) {}
}

@Selector

The @Selector decorator can be used to set the static $selector property used by Templates.

import { Selector } from 'jagwah';
​
@Selector('#navigation')
export class NavigationTemplate {
  constructor() {}
}

@Route

The @Route decorator can be used to set the static $route property used by Routes.

import { Route } from 'jagwah';
​
@Route('/user/:id')
export class UserProfileRoute {
  constructor() {}
}

@Middleware

The @Middleware decorator can be used to set the static $before and $after properties used by Routes.

import { Route, Middleware } from 'jagwah';
​
@Route('/account')
@Middleware('before', [new SignedInMiddleware('/account/sign/in')])
export class AccountRoute {
  constructor() {}
}