@player-ui/partial-match-fingerprint-plugin 0.0.1-next.1

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,33 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ class PartialMatchFingerprintPlugin {
6
+ constructor(registry) {
7
+ this.name = "partial-match-fingerprint";
8
+ this.registry = registry;
9
+ this.mapping = new Map();
10
+ }
11
+ apply(player) {
12
+ player.hooks.viewController.tap(this.name, (viewController) => {
13
+ viewController.hooks.view.tap(this.name, (view) => {
14
+ view.hooks.resolver.tap(this.name, (resolver) => {
15
+ resolver.hooks.afterResolve.tap(this.name, (resolved, node) => {
16
+ if (resolved && node && node.type === "asset" || node.type === "view") {
17
+ this.mapping.set(resolved.id, this.registry.get(resolved));
18
+ }
19
+ });
20
+ });
21
+ });
22
+ });
23
+ }
24
+ register(match, value) {
25
+ this.registry.set(match, value);
26
+ }
27
+ get(assetId) {
28
+ return this.mapping.get(assetId);
29
+ }
30
+ }
31
+
32
+ exports.PartialMatchFingerprintPlugin = PartialMatchFingerprintPlugin;
33
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1,19 @@
1
+ import { PlayerPlugin, Player } from '@player-ui/player';
2
+ import { Registry } from '@player-ui/partial-match-registry';
3
+
4
+ /**
5
+ * A player plugin to manage partial-match-mappings by asset id
6
+ * Automatically keeps track of all resolved asset id's and the value they match to in
7
+ * the partial match registry
8
+ */
9
+ declare class PartialMatchFingerprintPlugin implements PlayerPlugin {
10
+ name: string;
11
+ private registry;
12
+ private mapping;
13
+ constructor(registry: Registry<any>);
14
+ apply(player: Player): void;
15
+ register(match: any, value: any): void;
16
+ get(assetId: string): any;
17
+ }
18
+
19
+ export { PartialMatchFingerprintPlugin };
@@ -0,0 +1,29 @@
1
+ class PartialMatchFingerprintPlugin {
2
+ constructor(registry) {
3
+ this.name = "partial-match-fingerprint";
4
+ this.registry = registry;
5
+ this.mapping = new Map();
6
+ }
7
+ apply(player) {
8
+ player.hooks.viewController.tap(this.name, (viewController) => {
9
+ viewController.hooks.view.tap(this.name, (view) => {
10
+ view.hooks.resolver.tap(this.name, (resolver) => {
11
+ resolver.hooks.afterResolve.tap(this.name, (resolved, node) => {
12
+ if (resolved && node && node.type === "asset" || node.type === "view") {
13
+ this.mapping.set(resolved.id, this.registry.get(resolved));
14
+ }
15
+ });
16
+ });
17
+ });
18
+ });
19
+ }
20
+ register(match, value) {
21
+ this.registry.set(match, value);
22
+ }
23
+ get(assetId) {
24
+ return this.mapping.get(assetId);
25
+ }
26
+ }
27
+
28
+ export { PartialMatchFingerprintPlugin };
29
+ //# sourceMappingURL=index.esm.js.map
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@player-ui/partial-match-fingerprint-plugin",
3
+ "version": "0.0.1-next.1",
4
+ "private": false,
5
+ "publishConfig": {
6
+ "registry": "https://registry.npmjs.org"
7
+ },
8
+ "peerDependencies": {
9
+ "@player-ui/binding-grammar": "0.0.1-next.1"
10
+ },
11
+ "dependencies": {
12
+ "tapable": "1.1.3",
13
+ "@types/tapable": "^1.0.5",
14
+ "@babel/runtime": "7.15.4"
15
+ },
16
+ "main": "dist/index.cjs.js",
17
+ "module": "dist/index.esm.js",
18
+ "typings": "dist/index.d.ts"
19
+ }
package/src/index.ts ADDED
@@ -0,0 +1,47 @@
1
+ import type { Player, PlayerPlugin } from '@player-ui/player';
2
+ import type { Registry } from '@player-ui/partial-match-registry';
3
+ import type { Asset } from '@player-ui/types';
4
+
5
+ /**
6
+ * A player plugin to manage partial-match-mappings by asset id
7
+ * Automatically keeps track of all resolved asset id's and the value they match to in
8
+ * the partial match registry
9
+ */
10
+ export class PartialMatchFingerprintPlugin implements PlayerPlugin {
11
+ name = 'partial-match-fingerprint';
12
+ private registry: Registry<any>;
13
+ private mapping: Map<string, any>;
14
+
15
+ constructor(registry: Registry<any>) {
16
+ this.registry = registry;
17
+ this.mapping = new Map<string, any>();
18
+ }
19
+
20
+ apply(player: Player) {
21
+ player.hooks.viewController.tap(this.name, (viewController) => {
22
+ viewController.hooks.view.tap(this.name, (view) => {
23
+ view.hooks.resolver.tap(this.name, (resolver) => {
24
+ resolver.hooks.afterResolve.tap(this.name, (resolved, node) => {
25
+ if (
26
+ (resolved && node && node.type === 'asset') ||
27
+ node.type === 'view'
28
+ ) {
29
+ this.mapping.set(
30
+ (resolved as Asset).id,
31
+ this.registry.get(resolved as Asset)
32
+ );
33
+ }
34
+ });
35
+ });
36
+ });
37
+ });
38
+ }
39
+
40
+ register(match: any, value: any) {
41
+ this.registry.set(match, value);
42
+ }
43
+
44
+ get(assetId: string) {
45
+ return this.mapping.get(assetId);
46
+ }
47
+ }