@graphql-yoga/subscription 0.2.0-canary-f320652.0 → 2.0.0
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/createPubSub.spec.d.ts +1 -0
- package/index.js +21 -11
- package/index.mjs +17 -7
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/index.js
CHANGED
|
@@ -13,15 +13,20 @@ In modern JavaScript environments those are part of the global scope. However, i
|
|
|
13
13
|
You can provide polyfills to the 'createPubSub' function:
|
|
14
14
|
|
|
15
15
|
\`\`\`
|
|
16
|
-
// yarn install
|
|
17
|
-
import
|
|
18
|
-
import EventTarget from '@ungap/event-target'
|
|
16
|
+
// yarn install --exact event-target-polyfill@0.0.3
|
|
17
|
+
import 'event-target-polyfill'
|
|
19
18
|
|
|
19
|
+
const pubSub = createPubSub()
|
|
20
|
+
\`\`\`
|
|
21
|
+
|
|
22
|
+
Alternatively, you can provide your own custom implementation.
|
|
23
|
+
|
|
24
|
+
\`\`\`
|
|
20
25
|
const pubSub = createPubSub({
|
|
21
|
-
event: {
|
|
26
|
+
event: {
|
|
22
27
|
Event,
|
|
23
28
|
EventTarget,
|
|
24
|
-
}
|
|
29
|
+
}
|
|
25
30
|
})
|
|
26
31
|
\`\`\`
|
|
27
32
|
`);
|
|
@@ -37,8 +42,13 @@ const createPubSub = (config) => {
|
|
|
37
42
|
const target = (_a = config === null || config === void 0 ? void 0 : config.eventTarget) !== null && _a !== void 0 ? _a : new EventTarget();
|
|
38
43
|
return {
|
|
39
44
|
publish(routingKey, ...args) {
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
var _a;
|
|
46
|
+
const payload = (_a = args[1]) !== null && _a !== void 0 ? _a : args[0];
|
|
47
|
+
const topic = args[1] === undefined
|
|
48
|
+
? routingKey
|
|
49
|
+
: `${routingKey}:${args[0]}`;
|
|
50
|
+
const event = new Event(topic);
|
|
51
|
+
event.data = payload;
|
|
42
52
|
target.dispatchEvent(event);
|
|
43
53
|
},
|
|
44
54
|
subscribe(...[routingKey, id]) {
|
|
@@ -119,10 +129,10 @@ function pipe(a, ab, bc, cd, de, ef, fg, gh, hi) {
|
|
|
119
129
|
}
|
|
120
130
|
|
|
121
131
|
Object.defineProperty(exports, 'Repeater', {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
132
|
+
enumerable: true,
|
|
133
|
+
get: function () {
|
|
134
|
+
return repeater.Repeater;
|
|
135
|
+
}
|
|
126
136
|
});
|
|
127
137
|
exports.createPubSub = createPubSub;
|
|
128
138
|
exports.filter = filter;
|
package/index.mjs
CHANGED
|
@@ -10,15 +10,20 @@ In modern JavaScript environments those are part of the global scope. However, i
|
|
|
10
10
|
You can provide polyfills to the 'createPubSub' function:
|
|
11
11
|
|
|
12
12
|
\`\`\`
|
|
13
|
-
// yarn install
|
|
14
|
-
import
|
|
15
|
-
import EventTarget from '@ungap/event-target'
|
|
13
|
+
// yarn install --exact event-target-polyfill@0.0.3
|
|
14
|
+
import 'event-target-polyfill'
|
|
16
15
|
|
|
16
|
+
const pubSub = createPubSub()
|
|
17
|
+
\`\`\`
|
|
18
|
+
|
|
19
|
+
Alternatively, you can provide your own custom implementation.
|
|
20
|
+
|
|
21
|
+
\`\`\`
|
|
17
22
|
const pubSub = createPubSub({
|
|
18
|
-
event: {
|
|
23
|
+
event: {
|
|
19
24
|
Event,
|
|
20
25
|
EventTarget,
|
|
21
|
-
}
|
|
26
|
+
}
|
|
22
27
|
})
|
|
23
28
|
\`\`\`
|
|
24
29
|
`);
|
|
@@ -34,8 +39,13 @@ const createPubSub = (config) => {
|
|
|
34
39
|
const target = (_a = config === null || config === void 0 ? void 0 : config.eventTarget) !== null && _a !== void 0 ? _a : new EventTarget();
|
|
35
40
|
return {
|
|
36
41
|
publish(routingKey, ...args) {
|
|
37
|
-
|
|
38
|
-
|
|
42
|
+
var _a;
|
|
43
|
+
const payload = (_a = args[1]) !== null && _a !== void 0 ? _a : args[0];
|
|
44
|
+
const topic = args[1] === undefined
|
|
45
|
+
? routingKey
|
|
46
|
+
: `${routingKey}:${args[0]}`;
|
|
47
|
+
const event = new Event(topic);
|
|
48
|
+
event.data = payload;
|
|
39
49
|
target.dispatchEvent(event);
|
|
40
50
|
},
|
|
41
51
|
subscribe(...[routingKey, id]) {
|