forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArbiter-tests.ts
63 lines (44 loc) · 1.89 KB
/
Arbiter-tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Type definitions for Arbiter.js 1.0
// Project: http://arbiterjs.com/
// Definitions by: Arash Shakery <https://github.com/arash16>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
// May 22 2013
/// <reference path="Arbiter.d.ts" />
// Publish a simple message
Arbiter.publish('component/msg');
// Subscribe to a message
Arbiter.subscribe('component/msg', function () { });
// Pass data to subscribers
Arbiter.publish('component/msg', { "data": "value" });
// Force message bubbling
Arbiter.publish('component/msg', null, { cancelable: false });
// Allow late susbcribers to be notified of past messages
Arbiter.publish('component/msg', null, { persist: true });
// Fire subscribers asynchronously
Arbiter.publish('component/msg', null, { async: true });
// Subscribe to multiple messages at once
Arbiter.subscribe('component/msg, component/msg2', function () { });
Arbiter.subscribe(['component/msg', 'component/msg2'], function () { });
// Subscribe to multiple messages using a wildcard
Arbiter.subscribe('component/*', function () { });
// Subscribe to ALL messages
Arbiter.subscribe('*', function () { });
// Set subscriber priority
Arbiter.subscribe('msg', { priority: 10 }, function () { });
Arbiter.subscribe('msg', { priority: 20 }, function () { } ); // Called first!
// Execute a subscriber asynchronously
Arbiter.subscribe('msg', { async: true }, function () { });
// Ignore persisted messages
Arbiter.subscribe('msg', { persist: false }, function () { });
// Set the value of "this"
Arbiter.subscribe('msg', null, document.getElementById('x'),
function () {
this.innerHTML = "Message handled!";
});
// Unsubscribe from messages
var subscription_id = Arbiter.subscribe('msg', function () { });
Arbiter.unsubscribe(subscription_id);
// Re-subscribe to messages
Arbiter.resubscribe(subscription_id);
// Create a new message handler
var MyController = Arbiter.create()