@player-ui/stage-revert-data-plugin 0.4.0--canary.143.5197
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/dist/index.cjs.js +54 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.esm.js +50 -0
- package/dist/stage-revert-data-plugin.dev.js +11468 -0
- package/dist/stage-revert-data-plugin.prod.js +2 -0
- package/package.json +67 -0
- package/src/index.ts +80 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var player = require('@player-ui/player');
|
|
6
|
+
|
|
7
|
+
class StageRevertDataPlugin {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.name = "stage-revert-data-plugin";
|
|
10
|
+
}
|
|
11
|
+
apply(player$1) {
|
|
12
|
+
let dataController;
|
|
13
|
+
let commitTransitions;
|
|
14
|
+
let stageData;
|
|
15
|
+
let commitShadowModel = false;
|
|
16
|
+
const GatedDataMiddleware = new player.ValidationMiddleware(() => commitShadowModel ? void 0 : {
|
|
17
|
+
message: "staging data",
|
|
18
|
+
severity: "error"
|
|
19
|
+
}, { shouldIncludeInvalid: () => true });
|
|
20
|
+
player$1.hooks.dataController.tap(this.name, (dc) => {
|
|
21
|
+
dataController = dc;
|
|
22
|
+
dc.hooks.resolveDataStages.tap(this.name, (dataPipeline) => {
|
|
23
|
+
return stageData ? [...dataPipeline, GatedDataMiddleware] : [...dataPipeline];
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
player$1.hooks.flowController.tap(this.name, (flowController) => {
|
|
27
|
+
flowController.hooks.flow.tap(this.name, (flow) => {
|
|
28
|
+
flow.hooks.transition.tap(this.name, (from, to) => {
|
|
29
|
+
if (from) {
|
|
30
|
+
if (commitTransitions.includes(to.name)) {
|
|
31
|
+
commitShadowModel = true;
|
|
32
|
+
player$1.logger.debug("Shadow Model Data to be committed %s", GatedDataMiddleware.shadowModelPaths);
|
|
33
|
+
dataController.set(GatedDataMiddleware.shadowModelPaths);
|
|
34
|
+
}
|
|
35
|
+
commitShadowModel = false;
|
|
36
|
+
GatedDataMiddleware.shadowModelPaths.clear();
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
player$1.hooks.viewController.tap(this.name, (vc) => {
|
|
42
|
+
vc.hooks.resolveView.intercept({
|
|
43
|
+
call: (view, id, state) => {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
stageData = (_a = state == null ? void 0 : state.attributes) == null ? void 0 : _a.stageData;
|
|
46
|
+
commitTransitions = (_b = state == null ? void 0 : state.attributes) == null ? void 0 : _b.commitTransitions;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
exports.StageRevertDataPlugin = StageRevertDataPlugin;
|
|
54
|
+
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PlayerPlugin, Player } from '@player-ui/player';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* this plugin is supposed to stage/store changes in a local object/cache, until a transition happens,
|
|
5
|
+
* then changes are committed to the Data Model
|
|
6
|
+
*/
|
|
7
|
+
declare class StageRevertDataPlugin implements PlayerPlugin {
|
|
8
|
+
name: string;
|
|
9
|
+
apply(player: Player): void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { StageRevertDataPlugin };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ValidationMiddleware } from '@player-ui/player';
|
|
2
|
+
|
|
3
|
+
class StageRevertDataPlugin {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.name = "stage-revert-data-plugin";
|
|
6
|
+
}
|
|
7
|
+
apply(player) {
|
|
8
|
+
let dataController;
|
|
9
|
+
let commitTransitions;
|
|
10
|
+
let stageData;
|
|
11
|
+
let commitShadowModel = false;
|
|
12
|
+
const GatedDataMiddleware = new ValidationMiddleware(() => commitShadowModel ? void 0 : {
|
|
13
|
+
message: "staging data",
|
|
14
|
+
severity: "error"
|
|
15
|
+
}, { shouldIncludeInvalid: () => true });
|
|
16
|
+
player.hooks.dataController.tap(this.name, (dc) => {
|
|
17
|
+
dataController = dc;
|
|
18
|
+
dc.hooks.resolveDataStages.tap(this.name, (dataPipeline) => {
|
|
19
|
+
return stageData ? [...dataPipeline, GatedDataMiddleware] : [...dataPipeline];
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
player.hooks.flowController.tap(this.name, (flowController) => {
|
|
23
|
+
flowController.hooks.flow.tap(this.name, (flow) => {
|
|
24
|
+
flow.hooks.transition.tap(this.name, (from, to) => {
|
|
25
|
+
if (from) {
|
|
26
|
+
if (commitTransitions.includes(to.name)) {
|
|
27
|
+
commitShadowModel = true;
|
|
28
|
+
player.logger.debug("Shadow Model Data to be committed %s", GatedDataMiddleware.shadowModelPaths);
|
|
29
|
+
dataController.set(GatedDataMiddleware.shadowModelPaths);
|
|
30
|
+
}
|
|
31
|
+
commitShadowModel = false;
|
|
32
|
+
GatedDataMiddleware.shadowModelPaths.clear();
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
player.hooks.viewController.tap(this.name, (vc) => {
|
|
38
|
+
vc.hooks.resolveView.intercept({
|
|
39
|
+
call: (view, id, state) => {
|
|
40
|
+
var _a, _b;
|
|
41
|
+
stageData = (_a = state == null ? void 0 : state.attributes) == null ? void 0 : _a.stageData;
|
|
42
|
+
commitTransitions = (_b = state == null ? void 0 : state.attributes) == null ? void 0 : _b.commitTransitions;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { StageRevertDataPlugin };
|
|
50
|
+
//# sourceMappingURL=index.esm.js.map
|