ember-polling-push-updates 0.0.0 → 0.0.2
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.
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { service } from '@ember/service';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Decorates a route such that it refreshes the route when the path clears.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} cachePath The path as seen by mu-cache.
|
|
7
|
+
*/
|
|
8
|
+
export default function(cachePath) {
|
|
9
|
+
return function(klass) {
|
|
10
|
+
return class extends klass {
|
|
11
|
+
@service pushUpdates;
|
|
12
|
+
@service router;
|
|
13
|
+
|
|
14
|
+
refresh = () => this.router.refresh();
|
|
15
|
+
|
|
16
|
+
activate() {
|
|
17
|
+
super.activate(...arguments);
|
|
18
|
+
this.pushUpdates.monitorCache({
|
|
19
|
+
path: cachePath,
|
|
20
|
+
callback: this.refresh,
|
|
21
|
+
initial: false
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
deactivate() {
|
|
26
|
+
super.activate(...arguments);
|
|
27
|
+
this.pushUpdates.unMonitorCache({
|
|
28
|
+
path: cachePath,
|
|
29
|
+
callback: this.refresh,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { service } from '@ember/service';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Decorates a route such that it refreshes the route when the uri of the model clears.
|
|
5
|
+
*/
|
|
6
|
+
export default function(klass) {
|
|
7
|
+
return class extends klass {
|
|
8
|
+
@service pushUpdates;
|
|
9
|
+
|
|
10
|
+
lastModel = null;
|
|
11
|
+
|
|
12
|
+
async setupController(_controller, model) {
|
|
13
|
+
super.setupController(...arguments);
|
|
14
|
+
this.lastModel && await this.pushUpdates.unMonitorModel(this.lastModel);
|
|
15
|
+
this.lastModel = model;
|
|
16
|
+
await this.pushUpdates.monitorModel( model );
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async deactivate() {
|
|
20
|
+
super.deactivate(...arguments);
|
|
21
|
+
await this.pushUpdates.unMonitorModel( this.lastModel );
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -28,9 +28,12 @@ export default class PushUpdatesService extends Service {
|
|
|
28
28
|
if( ! this.tabUriP ) {
|
|
29
29
|
this.tabUriP = new Promise( async (acc, rej) => {
|
|
30
30
|
try {
|
|
31
|
-
const body = await fetch(`/polling/
|
|
31
|
+
const body = await fetch(`/polling/tab-ids`, {
|
|
32
|
+
method: 'POST',
|
|
33
|
+
headers: { 'Accept': 'application/vnd.api+json' }
|
|
34
|
+
});
|
|
32
35
|
const resp = await body.json();
|
|
33
|
-
const tabUri = resp.data.attributes.
|
|
36
|
+
const tabUri = resp.data.attributes.uri;
|
|
34
37
|
this.tabUri = tabUri;
|
|
35
38
|
acc(tabUri);
|
|
36
39
|
} catch (e) {
|