@polylith/core 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Registry.js +15 -15
- package/Service.js +1 -1
- package/ServiceObject.js +7 -7
- package/package-lock.json +31 -0
- package/package.json +1 -1
package/Registry.js
CHANGED
|
@@ -26,25 +26,25 @@ class Registry {
|
|
|
26
26
|
return this.services[name];
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
makeService(
|
|
30
|
-
obj.serviceObject = new ServiceOject(
|
|
29
|
+
makeService(serviceName, obj, methodsSpec) {
|
|
30
|
+
obj.serviceObject = new ServiceOject(serviceName);
|
|
31
31
|
|
|
32
32
|
obj.serviceObject.implementOn(obj, 'fire');
|
|
33
33
|
obj.serviceObject.implementOn(obj, 'listen');
|
|
34
34
|
obj.serviceObject.implementOn(obj, 'unlisten');
|
|
35
35
|
|
|
36
|
-
if (
|
|
37
|
-
registry.register(
|
|
36
|
+
if (serviceName) {
|
|
37
|
+
registry.register(serviceName, obj.serviceObject);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
if (methodsSpec) {
|
|
41
41
|
var methods = {};
|
|
42
42
|
|
|
43
|
-
methodsSpec.forEach(function(
|
|
44
|
-
if (obj[
|
|
45
|
-
methods[
|
|
43
|
+
methodsSpec.forEach(function(methodName) {
|
|
44
|
+
if (obj[methodName]) {
|
|
45
|
+
methods[methodName] = obj[methodName].bind(obj);
|
|
46
46
|
} else {
|
|
47
|
-
console.warn('method',
|
|
47
|
+
console.warn('method', methodName, 'not implemented on service', serviceName ? serviceName : '<unnamed service>')
|
|
48
48
|
}
|
|
49
49
|
});
|
|
50
50
|
|
|
@@ -52,10 +52,10 @@ class Registry {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
extendService(
|
|
56
|
-
var serviceObject = this.subscribe(
|
|
55
|
+
extendService(serviceName, obj, methodsSpec) {
|
|
56
|
+
var serviceObject = this.subscribe(serviceName);
|
|
57
57
|
|
|
58
|
-
obj.serviceObject = serviceObject || new ServiceOject(
|
|
58
|
+
obj.serviceObject = serviceObject || new ServiceOject(serviceName);
|
|
59
59
|
|
|
60
60
|
obj.serviceObject.implementOn(obj, 'fire');
|
|
61
61
|
obj.serviceObject.implementOn(obj, 'listen');
|
|
@@ -64,11 +64,11 @@ class Registry {
|
|
|
64
64
|
if (methodsSpec) {
|
|
65
65
|
var methods = {};
|
|
66
66
|
|
|
67
|
-
methodsSpec.forEach(function(
|
|
68
|
-
if (obj[
|
|
69
|
-
methods[
|
|
67
|
+
methodsSpec.forEach(function(methodName) {
|
|
68
|
+
if (obj[methodName]) {
|
|
69
|
+
methods[methodName] = obj[methodName].bind(obj);
|
|
70
70
|
} else {
|
|
71
|
-
console.warn('method',
|
|
71
|
+
console.warn('method', methodName, 'not implemented on service', serviceName ? serviceName : '<unnamed service>')
|
|
72
72
|
}
|
|
73
73
|
});
|
|
74
74
|
|
package/Service.js
CHANGED
|
@@ -21,7 +21,7 @@ export class Service {
|
|
|
21
21
|
if (this[name]) {
|
|
22
22
|
methods[name] = this[name].bind(this);
|
|
23
23
|
} else {
|
|
24
|
-
console.warn('method', name, 'not implemented on service', this.name ? name : '<unnamed service>')
|
|
24
|
+
console.warn('method', name, 'not implemented on service', this.name ? this.name : '<unnamed service>')
|
|
25
25
|
}
|
|
26
26
|
}, this);
|
|
27
27
|
|
package/ServiceObject.js
CHANGED
|
@@ -11,21 +11,21 @@ export class ServiceOject extends EventBus {
|
|
|
11
11
|
|
|
12
12
|
assignMethod(name, method) {
|
|
13
13
|
// if there is already a listener, unbind and force invoking
|
|
14
|
-
var bind = this.bound || !this.listeners[name];
|
|
14
|
+
var bind = this.bound || !this.listeners[name];
|
|
15
15
|
|
|
16
16
|
if (bind) {
|
|
17
17
|
this[name] = method;
|
|
18
18
|
} else {
|
|
19
19
|
// this may be a reassignment, but that's okay.
|
|
20
|
-
this
|
|
20
|
+
this[name] = this.invoke.bind(this, name)
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
this.methods.push(name);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
unbindMethod(name) {
|
|
27
|
-
if (this[
|
|
28
|
-
this
|
|
27
|
+
if (this[name]) {
|
|
28
|
+
this[name] = this.invoke.bind(this, name)
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -37,9 +37,9 @@ export class ServiceOject extends EventBus {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
implement(methods) {
|
|
40
|
-
var
|
|
40
|
+
var names = Object.keys(methods);
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
names.forEach(function(name) {
|
|
43
43
|
if (methods[name]) {
|
|
44
44
|
this.assignMethod(name, methods[name])
|
|
45
45
|
|
|
@@ -54,6 +54,6 @@ export class ServiceOject extends EventBus {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
async asyncInvoke(name, ...args) {
|
|
57
|
-
return this.
|
|
57
|
+
return await this.asyncFire(name, ...args);
|
|
58
58
|
}
|
|
59
59
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@polylith/core",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"lockfileVersion": 2,
|
|
5
|
+
"requires": true,
|
|
6
|
+
"packages": {
|
|
7
|
+
"": {
|
|
8
|
+
"name": "@polylith/core",
|
|
9
|
+
"version": "0.0.1",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"uuid": "^8.3.2"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"node_modules/uuid": {
|
|
16
|
+
"version": "8.3.2",
|
|
17
|
+
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
|
|
18
|
+
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
|
|
19
|
+
"bin": {
|
|
20
|
+
"uuid": "dist/bin/uuid"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"uuid": {
|
|
26
|
+
"version": "8.3.2",
|
|
27
|
+
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
|
|
28
|
+
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg=="
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|