Home Reference Source Test Repository

Function

Static Public Summary
public

channel(channelName: String): *

Sets up the channel for subcriptions.

public

highlight(el: *, words: *, options: *): *

public

publish(topic: String, channel: String): *

Decorator for publishing on an event bus (postal).

public

subscribe(topic: String, options: Object): *

Decorator for listening on an event bus (postal).

Static Public

public channel(channelName: String): * source

Sets up the channel for subcriptions. Keep in mind that after you use it, all other subscriptions underneath will use the same channel

Params:

NameTypeAttributeDescription
channelName String

Channel name for the class

Return:

*

Example:

import "publish" from "path/to/core/decorators/publish"

class FooComponent () {
  @subscribe("foo.some.other")
  @channel("foobar")
  anotherMethod() {
    // ...
  }
  @subscribe("foo.yet.another")
  anotherMethod() {
    // Still on the "foobar channel"
  }
  @subscribe("foo.yet.another")
  @channel("another")
  anotherMethod() {
    // Now we're on another channel
  }
}

See:

public highlight(el: *, words: *, options: *): * source

Params:

NameTypeAttributeDescription
el *
words *
options *

Return:

*

public publish(topic: String, channel: String): * source

Decorator for publishing on an event bus (postal). Whatever the decorated function returns gets published as the data. Will search the class for a channel, or use / by default.

Params:

NameTypeAttributeDescription
topic String

Topic to publish on

channel String

Channel to publish on

Return:

*

Example:

import "publish" from "path/to/core/decorators/publish"

class FooComponent () {
  @publish("foo.some.message")
  someMethod() {
    return {
      my: "data"
    };
  }
  @publish("foo.some.other")
  anotherMethod() {
    // ...
  }
}

public subscribe(topic: String, options: Object): * source

Decorator for listening on an event bus (postal).
Will search the class for a channel, or use / by default.
NOTE: You have to call this.subscribe() in the constructor in order to have postal actually attatch the listeners correctly.

Params:

NameTypeAttributeDescription
topic String

Topic to listen for

options Object

Objects for the subscription

Return:

*

Example:

Default Channel
import publish from "path/to/core/decorators/publish"

class FooComponent () {
  constructor() {
    // This is required
    this.subscribe();
  }
  @subscribe("foo.some.message")
  someMethod(data, evnelope, subscription) {
    
  }
  @subscribe("foo.some.other")
  anotherMethod(data, evnelope, subscription) {
    // ...
  }
}
Custom Channel
import publish from "path/to/core/decorators/publish"

class FooComponent () {
  constructor() {
    // This is required
    this.subscribe();
  }
  @subscribe("foo.some.message", "custom")
  someMethod(data, envelope, subscription) {
    // ...
  }
}
Channel decorator
import publish from "path/to/core/decorators/publish";
import channel from "path/to/core/decorators/channel"

class FooComponent () {
  constructor() {
    // This is required
    this.subscribe();
  }
  @subscribe("foo.some.message")
  @channel("custom")
  someMethod(data, envelope, subscription) {
    // ...
  }
}