fh-wfm-mediator
Advanced tools
Comparing version 0.2.0-rc3 to 0.3.0-rc2
"use strict"; | ||
var angular = require("angular"); | ||
var mediator_1 = require("../mediator"); | ||
const angular = require("angular"); | ||
const mediator = require("../mediator"); | ||
angular.module('wfm.core.mediator', ['ng']) | ||
.factory('mediator', function mediatorService($q) { | ||
var originalRequest = mediator_1.default.request; | ||
let originalRequest = mediator.request; | ||
// monkey patch the request function, wrapping the returned promise as an angular promise | ||
mediator_1.default.request = function () { | ||
var promise = originalRequest.apply(mediator_1.default, arguments); | ||
mediator.request = function () { | ||
let promise = originalRequest.apply(mediator, arguments); | ||
return $q.when(promise); | ||
}; | ||
mediator_1.default.subscribeForScope = function (topic, scope, fn) { | ||
var subscriber = mediator_1.default.subscribe(topic, fn); | ||
mediator.subscribeForScope = function (topic, scope, fn) { | ||
let subscriber = mediator.subscribe(topic, fn); | ||
scope.$on('$destroy', function () { | ||
mediator_1.default.remove(topic, subscriber.id); | ||
mediator.remove(topic, subscriber.id); | ||
}); | ||
return subscriber; | ||
}; | ||
return mediator_1.default; | ||
return mediator; | ||
}); | ||
@@ -21,0 +21,0 @@ Object.defineProperty(exports, "__esModule", { value: true }); |
"use strict"; | ||
var Promise = require("bluebird"); | ||
var _ = require("lodash"); | ||
var Topics = (function () { | ||
function Topics(mediator) { | ||
const Promise = require("bluebird"); | ||
const _ = require("lodash"); | ||
class Topics { | ||
constructor(mediator) { | ||
this.mediator = mediator; | ||
@@ -15,6 +15,6 @@ this.subscriptions = {}; | ||
*/ | ||
Topics.prototype.withPrefix = function (prefix) { | ||
withPrefix(prefix) { | ||
this.prefix = prefix; | ||
return this; | ||
}; | ||
} | ||
; | ||
@@ -29,6 +29,6 @@ /** | ||
*/ | ||
Topics.prototype.withEntity = function (entity) { | ||
withEntity(entity) { | ||
this.entity = entity; | ||
return this; | ||
}; | ||
} | ||
; | ||
@@ -40,5 +40,5 @@ /** | ||
*/ | ||
Topics.prototype.addSubscription = function (topic, fn) { | ||
addSubscription(topic, fn) { | ||
this.subscriptions[topic] = this.mediator.subscribe(topic, fn); | ||
}; | ||
} | ||
; | ||
@@ -52,5 +52,5 @@ /** | ||
*/ | ||
Topics.prototype.getTopic = function (topicName, prefix) { | ||
getTopic(topicName, prefix) { | ||
// create, done => done:wfm:user:create | ||
var parts = _.compact([this.prefix, this.entity, topicName]); | ||
let parts = _.compact([this.prefix, this.entity, topicName]); | ||
if (prefix) { | ||
@@ -60,3 +60,3 @@ parts.unshift(prefix); | ||
return parts.join(':'); | ||
}; | ||
} | ||
; | ||
@@ -72,7 +72,7 @@ /** | ||
*/ | ||
Topics.prototype.on = function (method, fn) { | ||
var topic = this.getTopic(method); | ||
on(method, fn) { | ||
let topic = this.getTopic(method); | ||
this.addSubscription(topic, this.wrapInMediatorPromise(method, fn)); | ||
return this; | ||
}; | ||
} | ||
; | ||
@@ -85,7 +85,7 @@ /** | ||
*/ | ||
Topics.prototype.onDone = function (method, fn) { | ||
var topic = this.getTopic(method, 'done'); | ||
onDone(method, fn) { | ||
let topic = this.getTopic(method, 'done'); | ||
this.addSubscription(topic, fn.bind(this)); | ||
return this; | ||
}; | ||
} | ||
; | ||
@@ -98,7 +98,7 @@ /** | ||
*/ | ||
Topics.prototype.onError = function (method, fn) { | ||
var topic = this.getTopic(method, 'error'); | ||
onError(method, fn) { | ||
let topic = this.getTopic(method, 'error'); | ||
this.addSubscription(topic, fn.bind(this)); | ||
return this; | ||
}; | ||
} | ||
; | ||
@@ -108,5 +108,5 @@ /** | ||
*/ | ||
Topics.prototype.unsubscribeAll = function () { | ||
var subId; | ||
for (var topic in this.subscriptions) { | ||
unsubscribeAll() { | ||
let subId; | ||
for (let topic in this.subscriptions) { | ||
if (this.subscriptions.hasOwnProperty(topic)) { | ||
@@ -117,3 +117,3 @@ subId = this.subscriptions[topic].id; | ||
} | ||
}; | ||
} | ||
; | ||
@@ -127,5 +127,5 @@ /** | ||
*/ | ||
Topics.prototype.request = function (topic, params, options) { | ||
request(topic, params, options) { | ||
return this.mediator.request(this.getTopic(topic), params, options); | ||
}; | ||
} | ||
; | ||
@@ -139,4 +139,4 @@ /** | ||
*/ | ||
Topics.prototype.wrapInMediatorPromise = function (method, fn) { | ||
var self = this; | ||
wrapInMediatorPromise(method, fn) { | ||
const self = this; | ||
function publishDone(result) { | ||
@@ -146,3 +146,3 @@ if (_.isUndefined(result)) { | ||
} | ||
var topic = self.getTopic(method, 'done'); | ||
let topic = self.getTopic(method, 'done'); | ||
if (_.has(result, 'id')) { | ||
@@ -158,3 +158,3 @@ topic = [topic, result.id].join(':'); | ||
function publishError(error) { | ||
var topic = self.getTopic(method, 'error'); | ||
let topic = self.getTopic(method, 'error'); | ||
if (_.has(error, 'id')) { | ||
@@ -170,7 +170,6 @@ topic = [topic, error.id].join(':'); | ||
}; | ||
}; | ||
return Topics; | ||
}()); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = Topics; | ||
} | ||
} | ||
; | ||
module.exports = Topics; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "fh-wfm-mediator", | ||
"version": "0.2.0-rc3", | ||
"version": "0.3.0-rc2", | ||
"description": "An implementation of the mediator pattern for use with WFM", | ||
@@ -10,9 +10,4 @@ "main": "lib/angular/mediator-ng.js", | ||
"vuln": "nsp check", | ||
"prepublish": "tsc" | ||
"build": "rm -rf lib/; tsc" | ||
}, | ||
"files": [ | ||
"lib/angular/mediator-ng.js", | ||
"lib/mediator.js", | ||
"lib/topics/index.js" | ||
], | ||
"keywords": [ | ||
@@ -35,6 +30,6 @@ "wfm", | ||
"@types/mocha": "^2.2.38", | ||
"@types/node": "^7.0.5", | ||
"@types/sinon": "^1.16.34", | ||
"chai": "^3.5.0", | ||
"grunt": "^1.0.1", | ||
"grunt-eslint": "^19.0.0", | ||
"grunt-mocha-test": "^0.13.2", | ||
@@ -41,0 +36,0 @@ "grunt-tslint": "^4.0.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22901
11
278
1