Class: App

App(definition) → {App}

Web-friendly application framework for building single-page applications with Fabric-based networking and storage.

Constructor

new App(definition) → {App}

Generic bundle for building Fabric applications.
Parameters:
Name Type Description
definition Object Application definition. See `config` for examples.
Properties:
Name Type Description
components Collection Interface elements.
stash Store Routable Datastore.
Source:
Returns:
Returns an instance of `App`.
Type
App

Extends

Methods

(async) _GET(path) → {Promise}

Retrieve a value from the Service's state.
Parameters:
Name Type Description
path String Path of the value to retrieve.
Overrides:
Source:
Returns:
Resolves with the result.
Type
Promise

(async) _PUT(path, value, commitopt) → {Promise}

Store a value in the Service's state.
Parameters:
Name Type Attributes Default Description
path String Path to store the value at.
value Object Document to store.
commit Boolean <optional>
false Sign the resulting state.
Overrides:
Source:
Returns:
Resolves with with stored document.
Type
Promise

(async) _registerActor(actor) → {Promise}

Register an Actor with the Service.
Parameters:
Name Type Description
actor Object Instance of the Actor.
Overrides:
Source:
Returns:
Resolves upon successful registration.
Type
Promise

_registerService(name, Service) → {Service}

Registers a named Service with the application. Services are standardized interfaces for Fabric contracts, emitting Message events with a predictable lifecycle.
Parameters:
Name Type Description
name String Internal name of the service.
Service Class The ES6 class definition implementing Service.
Source:
Returns:
The registered service instance.
Type
Service

(async) _send(message)

Sends a message.
Parameters:
Name Type Description
message Mixed Message to send.
Overrides:
Source:

attach(element) → {App}

Configure the Application to use a specific element.
Parameters:
Name Type Description
element DOMElement DOM element to bind to.
Source:
Returns:
Configured instance of the Application.
Type
App

beat() → {Service}

Compute latest state.
Overrides:
Source:
Fires:
  • Message#event:beat
Returns:
Type
Service

(async) connect(notify) → {Promise}

Attach to network.
Parameters:
Name Type Default Description
notify Boolean true Commit to changes.
Overrides:
Source:
Returns:
Resolves to Fabric.
Type
Promise

consume(resources) → {App}

Define the Application's resources from an existing resource map.
Parameters:
Name Type Description
resources Object Map of resource definitions by name.
Source:
Returns:
Configured instance of the Application.
Type
App

(async) defer(authority) → {App}

Defer control of this application to an outside authority.
Parameters:
Name Type Description
authority String Hostname to trust.
Source:
Returns:
The configured application as deferred to `authority`.
Type
App

(async) define(name, structure) → {Object}

Define a Resource, or "Type", used by the application.
Parameters:
Name Type Description
name String Human-friendly name for the Resource.
structure Object Map of attribute names -> definitions.
Source:
Returns:
[description]
Type
Object

envelop(selector) → {App}

Use a CSS selector to find an element in the current document's tree and bind to it as the render target.
Parameters:
Name Type Description
selector String CSS selector.
Source:
Returns:
Instance of app with bound element.
Type
App

get(path) → {Mixed}

Retrieve a key from the State.
Parameters:
Name Type Description
path Path Key to retrieve.
Overrides:
Source:
Returns:
Type
Mixed

handler(message) → {Service}

Default route handler for an incoming message. Follows the Activity Streams 2.0 spec: https://www.w3.org/TR/activitystreams-core/
Parameters:
Name Type Description
message Activity Message object.
Overrides:
Source:
Returns:
Chainable method.
Type
Service

init()

Called by Web Components. TODO: move to @fabric/http/types/spa
Overrides:
Source:

lock(durationopt) → {Boolean}

Attempt to acquire a lock for `duration` seconds.
Parameters:
Name Type Attributes Default Description
duration Number <optional>
1000 Number of milliseconds to hold lock.
Overrides:
Source:
Returns:
true if locked, false if unable to lock.
Type
Boolean

render() → {String}

Get the output of our program.
Source:
Returns:
Output of the program.
Type
String

(async) route(msg) → {Promise}

Resolve a State from a particular Message object.
Parameters:
Name Type Description
msg Message Explicit Fabric Message.
Overrides:
Source:
Returns:
Resolves with resulting State.
Type
Promise

(async) send(channel, message) → {Service}

Send a message to a channel.
Parameters:
Name Type Description
channel String Channel name to which the message will be sent.
message String Content of the message to send.
Overrides:
Source:
Returns:
Chainable method.
Type
Service

set(path) → {Mixed}

Set a key in the State to a particular value.
Parameters:
Name Type Description
path Path Key to retrieve.
Overrides:
Source:
Returns:
Type
Mixed

(async) start() → {Promise}

Start the program.
Overrides:
Source:
Returns:
Type
Promise

(async) stop() → {Promise}

Stop the program.
Source:
Returns:
Type
Promise

tick() → {Number}

Move forward one clock cycle.
Overrides:
Source:
Returns:
Type
Number

trust(source) → {Service}

Explicitly trust all events from a known source.
Parameters:
Name Type Description
source EventEmitter Emitter of events.
Overrides:
Source:
Returns:
Instance of Service after binding events.
Type
Service

use(name, definition) → {App}

Define a named Resource.
Parameters:
Name Type Description
name String Human-friendly name for this resource.
definition Object Map of configuration values.
Source:
Returns:
Configurated instance of the App.
Type
App