Skip to content

Base application runner for Cerebral, Cerebral Router and Baobab

Notifications You must be signed in to change notification settings

salespreso/sp-application

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SalesPreso application

Application structure that allows interconnection with other applications (combining routes and expressing parent/child relationships)

Example
import {
  Application, Register, extendClass, getChildrenWithContext
} from "sp-application";

API Reference

Application

Defines the interface needed to connect new components/stores/routes etc. the to application as a whole. Note in the example that decorators are called with "@" not "//@", but the documentation tool will accidently parse it.

//@application()
class Foo {
  static get routes() {
    return {
      "/myfoos": {
        "/": "openIndex",
        "/:id": "openDetailPage"
      }
    };
  }

  static get signals() {
    return {
      "openIndex": [setPage],
      "openDetailPage": [setPage, fetchStuff]
    };
  }

  static get store() {
    return {
      hai: true
    };
  }
}
Methods

Application.store() -> Object

Variables to be added to the store

Returns Object

Example
{
 storeData: "foo"
}

#### `Application.routes() -> Object` Cerebral router signals paths
Returns Object

Example
{
  "/messages/": "messageList",
  "/messages/:id/": "message"
}

#### `Application.signals() -> Object` Signal/action pairings for cerebral and cerebral router
Returns Object

Example
{
  "action": [action1, action2, action3]
}

application.decorators

Decorators [application.decorators]

Methods

Decorators.parent(String value) -> Function

Adds the parent value to a class. Used to set a child application to a parent application. For example, if I have the `appointments` app, after using this decorator @parent("ui"), it changes it to become "ui.appointments". Note in the example that decorators are called with "@" not "//@", but the documentation tool will accidently parse it.


Params
Type Parameter Description
String value
Returns Function

Example
//@parent("parentApp")
//@application()
class MyApp {

}

#### `Decorators.application([String value]) -> Function` Register an application, adding it to the application runner. Note in the example that decorators are called with "@" not "//@", but the documentation tool will accidently parse it.
Params
Type Parameter Description
String value Name of the application (must be unique). If not supplied, then uses the lowercase name of the class
Returns Function

Example
//@application()
class MyApp {

}

application.register

Register [application.register]

Global registration class. Used for dynamically importing applications and middleware on startup.

Methods

Register.unregister(String name)

Unregister a module


Params
Type Parameter Description
String name

#### `Register.import((string|string[]) paths) -> Promise` Dynamically loads a module
Params
Type Parameter Description
(string|string[]) paths Module(s) to import
Returns Promise

#### `Register.get(String name)` Return a registered plugin
Params
Type Parameter Description
String name

#### `Register.register(String name, Function module)` Register a plugin
Params
Type Parameter Description
String name
Function module

application.runner

ApplicationRunner [application.runner]

Properties

ApplicationRunner.registered


##### **Methods** #### `ApplicationRunner.add(String name, Application module)`
Params
Type Parameter Description
String name
Application module

#### `ApplicationRunner.remove(String name)`
Params
Type Parameter Description
String name

#### `ApplicationRunner.createRoutes() -> Object`
Returns Object

#### `ApplicationRunner.createSignals() -> Object`
Returns Object

#### `ApplicationRunner.createStore() -> Object`
Returns Object

application.util

Util [application.util]

Methods

Util.extendClass(Function classA, Function classB)

Copies all static and prototype methods/fields from classB to classA IF they don't already exist. Consider this like _.defaults in lodash for classes.


Params
Type Parameter Description
Function classA The class to extend
Function classB The class we're copying

About

Base application runner for Cerebral, Cerebral Router and Baobab

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published