Skip to content

Commit

Permalink
Removed cloning inside monitor.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaronius committed Feb 3, 2018
1 parent ca88851 commit 0624dd6
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/createMonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,37 @@ module.exports = function(container) {
reportRuleConditionFailed: noop,
getPublicMonitor: function() {
// Because the monitor is intended for debugging purposes only,
// we don't want to waste precious cycles on it unless a consumer requests it.
// we don't want to waste precious cycles on it until a consumer is actually going to use it.
if (!publicMonitor) {
logger.warn('The _satellite.__monitor API may change in any way ' +
'at any time and negatively impacts performance. Use at your own ' +
'risk and only for debugging.');

var emitter = mitt();

var clone = function(obj) {
return JSON.parse(JSON.stringify(obj));
};

monitor.reportRuleTriggered = function(rule) {
emitter.emit('ruleTriggered', {
rule: clone(rule)
rule: rule
});
};

monitor.reportRuleCompleted = function(rule) {
emitter.emit('ruleCompleted', {
rule: clone(rule)
rule: rule
});
};

monitor.reportRuleConditionFailed = function(rule, condition) {
emitter.emit('ruleConditionFailed', {
rule: clone(rule),
condition: clone(condition)
rule: rule,
condition: condition
});
};

publicMonitor = {
on: emitter.on,
off: emitter.off,
getContainer: clone.bind(container)
container: container
};
}

Expand Down

0 comments on commit 0624dd6

Please sign in to comment.