-
Notifications
You must be signed in to change notification settings - Fork 0
/
emitter.js
69 lines (61 loc) · 1.46 KB
/
emitter.js
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
64
65
66
67
68
69
/**
* @license MIT http://troopjs.mit-license.org/
*/
define([
"troopjs-core/emitter/composition",
"./config",
"./executor"
], function (Emitter, config, executor) {
"use strict";
/**
* A static version of {@link core.emitter.composition} with memorization.
*
* ## Memorized emitting
*
* A emitter event will memorize the "current" value of each event. Each executor may have it's own interpretation
* of what "current" means.
*
* @class hub.emitter
* @extend core.emitter.composition
* @mixin hub.config
* @inheritdoc
* @singleton
*/
/**
* @method create
* @static
* @hide
*/
/**
* @method extend
* @static
* @hide
*/
/**
* @method constructor
* @hide
*/
var UNDEFINED;
var MEMORY = config.emitter.memory;
var HANDLERS = config.emitter.handlers;
var EXECUTOR = config.emitter.executor;
return Emitter.create(function (key, value) {
var me = this;
me[key] = value;
return me;
}.call({
"displayName": "hub/emitter",
/**
* Returns value in handlers MEMORY
* @param {String} type event type to peek at
* @param {*} [value] Value to use _only_ if no memory has been recorder
* @return {*} Value in MEMORY
*/
"peek": function (type, value) {
var handlers;
return (handlers = this[HANDLERS][type]) === UNDEFINED || !handlers.hasOwnProperty(MEMORY)
? value
: handlers[MEMORY];
}
}, EXECUTOR, executor));
});