react-obsidian 2.30.0 → 2.31.0-alpha.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.
- package/dist/src/decorators/LifecycleBound.d.ts +1 -0
- package/dist/src/decorators/LifecycleBound.d.ts.map +1 -1
- package/dist/src/decorators/LifecycleBound.js +2 -1
- package/dist/src/decorators/LifecycleBound.js.map +1 -1
- package/dist/src/graph/ObjectGraph.d.ts +1 -0
- package/dist/src/graph/ObjectGraph.d.ts.map +1 -1
- package/dist/src/graph/ObjectGraph.js +4 -0
- package/dist/src/graph/ObjectGraph.js.map +1 -1
- package/dist/src/injectors/components/ComponentInjector.d.ts.map +1 -1
- package/dist/src/injectors/components/ComponentInjector.js +40 -3
- package/dist/src/injectors/components/ComponentInjector.js.map +1 -1
- package/dist/src/injectors/components/useGraph.d.ts +2 -1
- package/dist/src/injectors/components/useGraph.d.ts.map +1 -1
- package/dist/src/injectors/components/useGraph.js +9 -2
- package/dist/src/injectors/components/useGraph.js.map +1 -1
- package/dist/src/injectors/components/useGraphContainer.d.ts +6 -0
- package/dist/src/injectors/components/useGraphContainer.d.ts.map +1 -0
- package/dist/src/injectors/components/useGraphContainer.js +47 -0
- package/dist/src/injectors/components/useGraphContainer.js.map +1 -0
- package/dist/src/utils/packageAvailability.d.ts +2 -0
- package/dist/src/utils/packageAvailability.d.ts.map +1 -0
- package/dist/src/utils/packageAvailability.js +18 -0
- package/dist/src/utils/packageAvailability.js.map +1 -0
- package/dist/src/utils/reactAvailability.d.ts +0 -5
- package/dist/src/utils/reactAvailability.d.ts.map +1 -1
- package/dist/src/utils/reactAvailability.js +2 -26
- package/dist/src/utils/reactAvailability.js.map +1 -1
- package/dist/src/utils/reactNativeAvailability.d.ts +2 -0
- package/dist/src/utils/reactNativeAvailability.d.ts.map +1 -0
- package/dist/src/utils/reactNativeAvailability.js +16 -0
- package/dist/src/utils/reactNativeAvailability.js.map +1 -0
- package/dist/test/fixtures/RetainedLifecycleBoundGraph.d.ts +7 -0
- package/dist/test/fixtures/RetainedLifecycleBoundGraph.d.ts.map +1 -0
- package/dist/test/fixtures/RetainedLifecycleBoundGraph.js +78 -0
- package/dist/test/fixtures/RetainedLifecycleBoundGraph.js.map +1 -0
- package/package.json +2 -1
- package/src/decorators/LifecycleBound.ts +2 -0
- package/src/graph/ObjectGraph.ts +4 -0
- package/src/injectors/components/ComponentInjector.tsx +8 -3
- package/src/injectors/components/useGraph.ts +10 -2
- package/src/injectors/components/useGraphContainer.tsx +19 -0
- package/src/utils/packageAvailability.ts +13 -0
- package/src/utils/reactAvailability.ts +2 -29
- package/src/utils/reactNativeAvailability.ts +13 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LifecycleBound.d.ts","sourceRoot":"","sources":["../../../src/decorators/LifecycleBound.ts"],"names":[],"mappings":"AAEA,KAAK,OAAO,GAAG;IACb,KAAK,CAAC,EAAE,WAAW,GAAG,SAAS,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"LifecycleBound.d.ts","sourceRoot":"","sources":["../../../src/decorators/LifecycleBound.ts"],"names":[],"mappings":"AAEA,KAAK,OAAO,GAAG;IACb,KAAK,CAAC,EAAE,WAAW,GAAG,SAAS,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;IAChD,gBAAgB,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;CACzC,CAAC;AAEF,wBAAgB,cAAc,CAAC,OAAO,CAAC,EAAE,OAAO,iBACzB,GAAG,SAMzB"}
|
|
@@ -4,9 +4,10 @@ exports.lifecycleBound = lifecycleBound;
|
|
|
4
4
|
const reflect_1 = require("../utils/reflect");
|
|
5
5
|
function lifecycleBound(options) {
|
|
6
6
|
return (constructor) => {
|
|
7
|
-
var _a;
|
|
7
|
+
var _a, _b;
|
|
8
8
|
reflect_1.Reflect.defineMetadata('isLifecycleBound', true, constructor);
|
|
9
9
|
reflect_1.Reflect.defineMetadata('lifecycleScope', (_a = options === null || options === void 0 ? void 0 : options.scope) !== null && _a !== void 0 ? _a : 'feature', constructor);
|
|
10
|
+
reflect_1.Reflect.defineMetadata('inactiveBehavior', (_b = options === null || options === void 0 ? void 0 : options.inactiveBehavior) !== null && _b !== void 0 ? _b : 'unmount', constructor);
|
|
10
11
|
return constructor;
|
|
11
12
|
};
|
|
12
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LifecycleBound.js","sourceRoot":"","sources":["../../../src/decorators/LifecycleBound.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"LifecycleBound.js","sourceRoot":"","sources":["../../../src/decorators/LifecycleBound.ts"],"names":[],"mappings":";;AAOA,wCAOC;AAdD,8CAAyC;AAOzC,SAAgB,cAAc,CAAC,OAAiB;IAC9C,OAAO,CAAC,WAAgB,EAAE,EAAE;;QAC1B,iBAAO,CAAC,cAAc,CAAC,kBAAkB,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;QAC9D,iBAAO,CAAC,cAAc,CAAC,gBAAgB,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,mCAAI,SAAS,EAAE,WAAW,CAAC,CAAC;QACnF,iBAAO,CAAC,cAAc,CAAC,kBAAkB,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,gBAAgB,mCAAI,SAAS,EAAE,WAAW,CAAC,CAAC;QAChG,OAAO,WAAW,CAAC;IACrB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -4,6 +4,7 @@ import { CircularDependenciesDetector } from './CircularDependenciesDetector';
|
|
|
4
4
|
export declare abstract class ObjectGraph<T = unknown> implements Graph {
|
|
5
5
|
protected _props?: T | undefined;
|
|
6
6
|
private propertyRetriever;
|
|
7
|
+
get inactiveBehavior(): 'unmount' | 'retain';
|
|
7
8
|
get name(): string;
|
|
8
9
|
constructor(_props?: T | undefined);
|
|
9
10
|
retrieve<Dependency>(property: string, receiver?: unknown, detector?: CircularDependenciesDetector): Dependency | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectGraph.d.ts","sourceRoot":"","sources":["../../../src/graph/ObjectGraph.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAI9E,8BAAsB,WAAW,CAAC,CAAC,GAAG,OAAO,CAAE,YAAW,KAAK;
|
|
1
|
+
{"version":3,"file":"ObjectGraph.d.ts","sourceRoot":"","sources":["../../../src/graph/ObjectGraph.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAI9E,8BAAsB,WAAW,CAAC,CAAC,GAAG,OAAO,CAAE,YAAW,KAAK;IAiBjD,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;IAhBhC,OAAO,CAAC,iBAAiB,CAA+B;IAExD,IAAI,gBAAgB,IAAI,SAAS,GAAG,QAAQ,CAE3C;IAED,IAAI,IAAI,IAAI,MAAM,CAQjB;gBAEqB,MAAM,CAAC,EAAE,CAAC,YAAA;IAIhC,QAAQ,CAAC,UAAU,EACjB,QAAQ,EAAE,MAAM,EAChB,QAAQ,CAAC,EAAE,OAAO,EAClB,QAAQ,CAAC,EAAE,4BAA4B,GACtC,UAAU,GAAG,SAAS;IAQzB,WAAW,CAAC,UAAU,EACpB,QAAQ,EAAE,MAAM,EAChB,QAAQ,CAAC,EAAE,OAAO,EAClB,QAAQ,CAAC,EAAE,4BAA4B,GACtC,UAAU,GAAG,SAAS;IAQzB,MAAM,CAAC,OAAO,EAAE,GAAG;CAGpB;AAID,wBAAgB,OAAO,CAAC,MAAM,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,GAAG,GAAG,MAAM,IAAI,aAAa,CAAC,WAAW,CAAC,CAEtG"}
|
|
@@ -11,6 +11,10 @@ const PropertyRetriever_1 = __importDefault(require("./properties/PropertyRetrie
|
|
|
11
11
|
const reflect_1 = require("../utils/reflect");
|
|
12
12
|
const object_1 = require("../utils/object");
|
|
13
13
|
class ObjectGraph {
|
|
14
|
+
get inactiveBehavior() {
|
|
15
|
+
var _a;
|
|
16
|
+
return (_a = reflect_1.Reflect.getMetadata('inactiveBehavior', this.constructor)) !== null && _a !== void 0 ? _a : 'unmount';
|
|
17
|
+
}
|
|
14
18
|
get name() {
|
|
15
19
|
const target = (0, object_1.getConstructorOrParentConstructor)(this.constructor, ObjectGraph.name);
|
|
16
20
|
if (reflect_1.Reflect.hasMetadata('memoizedName', target)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectGraph.js","sourceRoot":"","sources":["../../../src/graph/ObjectGraph.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"ObjectGraph.js","sourceRoot":"","sources":["../../../src/graph/ObjectGraph.ts"],"names":[],"mappings":";;;;;;AA6DA,0BAEC;AA/DD,gDAA6C;AAC7C,qDAAiD;AAEjD,uFAA+D;AAG/D,8CAA2C;AAC3C,4CAAoE;AAEpE,MAAsB,WAAW;IAG/B,IAAI,gBAAgB;;QAClB,OAAO,MAAA,iBAAO,CAAC,WAAW,CAAC,kBAAkB,EAAE,IAAI,CAAC,WAAW,CAAC,mCAAI,SAAS,CAAC;IAChF,CAAC;IAED,IAAI,IAAI;QACN,MAAM,MAAM,GAAG,IAAA,0CAAiC,EAAC,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;QACrF,IAAI,iBAAO,CAAC,WAAW,CAAC,cAAc,EAAE,MAAM,CAAC,EAAE,CAAC;YAChD,OAAO,iBAAO,CAAC,WAAW,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;QACrD,CAAC;QACD,MAAM,IAAI,GAAG,IAAA,mBAAQ,EAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACnC,iBAAO,CAAC,cAAc,CAAC,cAAc,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QACrD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,YAAsB,MAAU;QAAV,WAAM,GAAN,MAAM,CAAI;QAhBxB,sBAAiB,GAAG,IAAI,2BAAiB,CAAC,IAAI,CAAC,CAAC;QAiBtD,IAAA,8BAAa,EAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IAED,QAAQ,CACN,QAAgB,EAChB,QAAkB,EAClB,QAAuC;QAEvC,OAAO,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CACpC,QAAQ,EACR,QAAQ,EACR,QAAQ,CACiB,CAAC;IAC9B,CAAC;IAED,WAAW,CACT,QAAgB,EAChB,QAAkB,EAClB,QAAuC;QAEvC,OAAO,IAAI,CAAC,iBAAiB,CAAC,WAAW,CACvC,QAAQ,EACR,QAAQ,EACR,QAAQ,CACiB,CAAC;IAC9B,CAAC;IAED,MAAM,CAAC,OAAY;IAEnB,CAAC;CACF;AAhDD,kCAgDC;AAED,iBAAO,CAAC,GAAG,CAAC,WAAW,EAAE,mBAAmB,EAAE,aAAa,CAAC,CAAC;AAE7D,SAAgB,OAAO,CAAC,MAAwC;IAC9D,OAAO,iBAAO,CAAC,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,KAAK,aAAa,CAAC;AACpE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComponentInjector.d.ts","sourceRoot":"","sources":["../../../../src/injectors/components/ComponentInjector.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ComponentInjector.d.ts","sourceRoot":"","sources":["../../../../src/injectors/components/ComponentInjector.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoC,MAAM,OAAO,CAAC;AAEzD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAItD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAK5C,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC,MAAM,CAAC,CAAC,EACN,MAAM,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAClC,UAAU,EAAE,MAAM,GAAG,aAAa,CAAC,WAAW,CAAC,GAC9C,KAAK,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAMtC,OAAO,CAAC,aAAa;CAwBtB"}
|
|
@@ -1,12 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
5
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const react_1 =
|
|
39
|
+
const react_1 = __importStar(require("react"));
|
|
7
40
|
const hoist_non_react_statics_1 = __importDefault(require("hoist-non-react-statics"));
|
|
8
41
|
const PropsInjector_1 = __importDefault(require("./PropsInjector"));
|
|
9
42
|
const useGraph_1 = __importDefault(require("./useGraph"));
|
|
43
|
+
const useGraphContainer_1 = __importDefault(require("./useGraphContainer"));
|
|
10
44
|
const React_1 = require("../../utils/React");
|
|
11
45
|
const graphContext_1 = require("./graphContext");
|
|
12
46
|
const useInjectionToken_1 = require("./useInjectionToken");
|
|
@@ -22,9 +56,12 @@ class ComponentInjector {
|
|
|
22
56
|
const compare = isMemoized ? InjectionCandidate.compare : undefined;
|
|
23
57
|
return (0, React_1.genericMemo)((passedProps) => {
|
|
24
58
|
const injectionToken = (0, useInjectionToken_1.useInjectionToken)(keyOrGraph);
|
|
25
|
-
const
|
|
59
|
+
const containerRef = (0, react_1.useRef)(null);
|
|
60
|
+
const graph = (0, useGraph_1.default)(keyOrGraph, Target, passedProps, injectionToken, containerRef);
|
|
61
|
+
const Container = (0, useGraphContainer_1.default)(graph);
|
|
26
62
|
const proxiedProps = new PropsInjector_1.default(graph).inject(passedProps);
|
|
27
|
-
return (react_1.default.createElement(graphContext_1.GraphContext.Provider, { value: { injectionToken } },
|
|
63
|
+
return (react_1.default.createElement(graphContext_1.GraphContext.Provider, { value: { injectionToken } },
|
|
64
|
+
react_1.default.createElement(Container, { ref: containerRef }, Target(proxiedProps))));
|
|
28
65
|
}, compare);
|
|
29
66
|
}
|
|
30
67
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComponentInjector.js","sourceRoot":"","sources":["../../../../src/injectors/components/ComponentInjector.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ComponentInjector.js","sourceRoot":"","sources":["../../../../src/injectors/components/ComponentInjector.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAyD;AACzD,sFAA2D;AAE3D,oEAA4C;AAC5C,0DAAkC;AAClC,4EAAoD;AAEpD,6CAAqE;AACrE,iDAA8C;AAC9C,2DAAwD;AAExD,MAAqB,iBAAiB;IACpC,MAAM,CACJ,MAAkC,EAClC,UAA+C;QAE/C,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QACvD,IAAA,iCAAoB,EAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACtC,OAAO,OAAO,CAAC;IACjB,CAAC;IAEO,aAAa,CACnB,kBAA8C,EAC9C,UAA+C;QAE/C,MAAM,UAAU,GAAG,IAAA,2BAAmB,EAAC,kBAAkB,CAAC,CAAC;QAC3D,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,kBAAkB,CAAC;QACzE,MAAM,OAAO,GAAG,UAAU,CAAC,CAAC,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;QAEpE,OAAO,IAAA,mBAAW,EAAC,CAAC,WAAc,EAAE,EAAE;YACpC,MAAM,cAAc,GAAG,IAAA,qCAAiB,EAAC,UAAU,CAAC,CAAC;YACrD,MAAM,YAAY,GAAG,IAAA,cAAM,EAAC,IAAI,CAAC,CAAC;YAClC,MAAM,KAAK,GAAG,IAAA,kBAAQ,EAAI,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC;YACzF,MAAM,SAAS,GAAG,IAAA,2BAAiB,EAAC,KAAK,CAAC,CAAC;YAC3C,MAAM,YAAY,GAAG,IAAI,uBAAa,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YAElE,OAAO,CACL,8BAAC,2BAAY,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAC,cAAc,EAAC;gBAC5C,8BAAC,SAAS,IAAC,GAAG,EAAE,YAAY,IACzB,MAAM,CAAC,YAA+C,CAAC,CAC9C,CACU,CACzB,CAAC;QACJ,CAAC,EAAE,OAAO,CAAC,CAAC;IACd,CAAC;CACF;AAlCD,oCAkCC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
import { Constructable } from '../../types';
|
|
2
3
|
import { ObjectGraph } from '../../graph/ObjectGraph';
|
|
3
|
-
declare const _default: <P>(keyOrGraph: string | Constructable<ObjectGraph>, target: any, props?: Partial<P>, injectionToken?: string) => ObjectGraph<unknown>;
|
|
4
|
+
declare const _default: <P>(keyOrGraph: string | Constructable<ObjectGraph>, target: any, props?: Partial<P>, injectionToken?: string, containerRef?: React.RefObject<any>) => ObjectGraph<unknown>;
|
|
4
5
|
export default _default;
|
|
5
6
|
//# sourceMappingURL=useGraph.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGraph.d.ts","sourceRoot":"","sources":["../../../../src/injectors/components/useGraph.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useGraph.d.ts","sourceRoot":"","sources":["../../../../src/injectors/components/useGraph.ts"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;yBAItC,CAAC,cACH,MAAM,GAAG,aAAa,CAAC,WAAW,CAAC,UACvC,GAAG,UACH,OAAO,CAAC,CAAC,CAAC,mBACD,MAAM,iBACR,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC;AALrC,wBAyBE"}
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const react_1 = require("react");
|
|
7
7
|
const GraphRegistry_1 = __importDefault(require("../../graph/registry/GraphRegistry"));
|
|
8
8
|
const ReferenceCounter_1 = __importDefault(require("../../ReferenceCounter"));
|
|
9
|
-
exports.default = (keyOrGraph, target, props, injectionToken) => {
|
|
9
|
+
exports.default = (keyOrGraph, target, props, injectionToken, containerRef) => {
|
|
10
10
|
const [graph] = (0, react_1.useState)(() => {
|
|
11
11
|
const resolvedGraph = GraphRegistry_1.default.resolve(keyOrGraph, 'lifecycleOwner', props, injectionToken);
|
|
12
12
|
resolvedGraph.onBind(target);
|
|
@@ -14,7 +14,14 @@ exports.default = (keyOrGraph, target, props, injectionToken) => {
|
|
|
14
14
|
});
|
|
15
15
|
(0, react_1.useEffect)(() => {
|
|
16
16
|
ReferenceCounter_1.default.retain(graph);
|
|
17
|
-
return () =>
|
|
17
|
+
return () => {
|
|
18
|
+
const isCleanupCalledDueToActivityPause = containerRef === null || containerRef === void 0 ? void 0 : containerRef.current;
|
|
19
|
+
ReferenceCounter_1.default.release(graph, (g) => {
|
|
20
|
+
if (!isCleanupCalledDueToActivityPause) {
|
|
21
|
+
GraphRegistry_1.default.clear(g);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
};
|
|
18
25
|
}, [graph]);
|
|
19
26
|
return graph;
|
|
20
27
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGraph.js","sourceRoot":"","sources":["../../../../src/injectors/components/useGraph.ts"],"names":[],"mappings":";;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"useGraph.js","sourceRoot":"","sources":["../../../../src/injectors/components/useGraph.ts"],"names":[],"mappings":";;;;;AAAA,iCAAmD;AAGnD,uFAA+D;AAC/D,8EAAsD;AAEtD,kBAAe,CACb,UAA+C,EAC/C,MAAW,EACX,KAAkB,EAClB,cAAuB,EACvB,YAAmC,EACnC,EAAE;IAEF,MAAM,CAAC,KAAK,CAAC,GAAG,IAAA,gBAAQ,EAAC,GAAG,EAAE;QAC5B,MAAM,aAAa,GAAG,uBAAa,CAAC,OAAO,CAAC,UAAU,EAAE,gBAAgB,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC;QACjG,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC7B,OAAO,aAAa,CAAC;IACvB,CAAC,CAAC,CAAC;IACH,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,0BAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC/B,OAAO,GAAG,EAAE;YACV,MAAM,iCAAiC,GAAG,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,OAAO,CAAC;YAChE,0BAAgB,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE;gBACpC,IAAI,CAAC,iCAAiC,EAAE,CAAC;oBACvC,uBAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBACzB,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IACZ,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ObjectGraph } from '../../graph/ObjectGraph';
|
|
3
|
+
export default function useGraphContainer(graph: ObjectGraph): React.ForwardRefExoticComponent<{
|
|
4
|
+
children?: React.ReactNode | undefined;
|
|
5
|
+
} & React.RefAttributes<any>>;
|
|
6
|
+
//# sourceMappingURL=useGraphContainer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGraphContainer.d.ts","sourceRoot":"","sources":["../../../../src/injectors/components/useGraphContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAwC,MAAM,OAAO,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAetD,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,KAAK,EAAE,WAAW;;8BAE3D"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.default = useGraphContainer;
|
|
37
|
+
const react_1 = __importStar(require("react"));
|
|
38
|
+
const reactNativeAvailability_1 = require("../../utils/reactNativeAvailability");
|
|
39
|
+
const isRN = (0, reactNativeAvailability_1.isReactNativeAvailable)();
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports, global-require
|
|
41
|
+
const Element = isRN ? require('react-native').View : 'div';
|
|
42
|
+
const RetainContainer = (0, react_1.forwardRef)((props, ref) => (react_1.default.createElement(Element, { ref: ref, style: isRN ? undefined : { display: 'contents' } }, props.children)));
|
|
43
|
+
const PassthroughContainer = (0, react_1.forwardRef)((props) => (react_1.default.createElement(react_1.default.Fragment, null, props.children)));
|
|
44
|
+
function useGraphContainer(graph) {
|
|
45
|
+
return graph.inactiveBehavior === 'retain' ? RetainContainer : PassthroughContainer;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=useGraphContainer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGraphContainer.js","sourceRoot":"","sources":["../../../../src/injectors/components/useGraphContainer.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,oCAEC;AAlBD,+CAA6D;AAE7D,iFAA6E;AAE7E,MAAM,IAAI,GAAG,IAAA,gDAAsB,GAAE,CAAC;AACtC,iFAAiF;AACjF,MAAM,OAAO,GAAQ,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;AAEjE,MAAM,eAAe,GAAG,IAAA,kBAAU,EAAyB,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,CACzE,8BAAC,OAAO,IAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,IAAG,KAAK,CAAC,QAAQ,CAAW,CACjG,CAAC,CAAC;AAEH,MAAM,oBAAoB,GAAG,IAAA,kBAAU,EAAyB,CAAC,KAAK,EAAE,EAAE,CAAC,CACzE,8DAAG,KAAK,CAAC,QAAQ,CAAI,CACtB,CAAC,CAAC;AAEH,SAAwB,iBAAiB,CAAC,KAAkB;IAC1D,OAAO,KAAK,CAAC,gBAAgB,KAAK,QAAQ,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,oBAAoB,CAAC;AACtF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"packageAvailability.d.ts","sourceRoot":"","sources":["../../../src/utils/packageAvailability.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAUxD"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPackageAvailable = isPackageAvailable;
|
|
4
|
+
const cache = new Map();
|
|
5
|
+
function isPackageAvailable(name) {
|
|
6
|
+
if (cache.has(name))
|
|
7
|
+
return cache.get(name);
|
|
8
|
+
try {
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports, global-require
|
|
10
|
+
require(name);
|
|
11
|
+
cache.set(name, true);
|
|
12
|
+
}
|
|
13
|
+
catch (_a) {
|
|
14
|
+
cache.set(name, false);
|
|
15
|
+
}
|
|
16
|
+
return cache.get(name);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=packageAvailability.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"packageAvailability.js","sourceRoot":"","sources":["../../../src/utils/packageAvailability.ts"],"names":[],"mappings":";;AAEA,gDAUC;AAZD,MAAM,KAAK,GAAG,IAAI,GAAG,EAAmB,CAAC;AAEzC,SAAgB,kBAAkB,CAAC,IAAY;IAC7C,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC;IAC7C,IAAI,CAAC;QACH,iFAAiF;QACjF,OAAO,CAAC,IAAI,CAAC,CAAC;QACd,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACxB,CAAC;IAAC,WAAM,CAAC;QACP,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACzB,CAAC;IACD,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC;AAC1B,CAAC"}
|
|
@@ -4,9 +4,4 @@ export declare function isReactAvailable(): boolean;
|
|
|
4
4
|
* Used to provide helpful error messages for React-dependent features.
|
|
5
5
|
*/
|
|
6
6
|
export declare function createReactRequiredError<T = any>(featureName: string): T;
|
|
7
|
-
/**
|
|
8
|
-
* Creates a class constructor that throws an error when instantiated if React is not available.
|
|
9
|
-
* Used for features like Model that need to be constructable.
|
|
10
|
-
*/
|
|
11
|
-
export declare function createReactRequiredClass<T = any>(className: string): T;
|
|
12
7
|
//# sourceMappingURL=reactAvailability.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactAvailability.d.ts","sourceRoot":"","sources":["../../../src/utils/reactAvailability.ts"],"names":[],"mappings":"AAEA,wBAAgB,gBAAgB,IAAI,OAAO,
|
|
1
|
+
{"version":3,"file":"reactAvailability.d.ts","sourceRoot":"","sources":["../../../src/utils/reactAvailability.ts"],"names":[],"mappings":"AAEA,wBAAgB,gBAAgB,IAAI,OAAO,CAE1C;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,GAAG,GAAG,EAAE,WAAW,EAAE,MAAM,GAAG,CAAC,CAOxE"}
|
|
@@ -2,21 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isReactAvailable = isReactAvailable;
|
|
4
4
|
exports.createReactRequiredError = createReactRequiredError;
|
|
5
|
-
|
|
6
|
-
let reactAvailableCache;
|
|
5
|
+
const packageAvailability_1 = require("./packageAvailability");
|
|
7
6
|
function isReactAvailable() {
|
|
8
|
-
|
|
9
|
-
return reactAvailableCache;
|
|
10
|
-
}
|
|
11
|
-
try {
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports, global-require
|
|
13
|
-
require('react');
|
|
14
|
-
reactAvailableCache = true;
|
|
15
|
-
}
|
|
16
|
-
catch (_a) {
|
|
17
|
-
reactAvailableCache = false;
|
|
18
|
-
}
|
|
19
|
-
return reactAvailableCache;
|
|
7
|
+
return (0, packageAvailability_1.isPackageAvailable)('react');
|
|
20
8
|
}
|
|
21
9
|
/**
|
|
22
10
|
* Creates a function that throws an error when called if React is not available.
|
|
@@ -28,16 +16,4 @@ function createReactRequiredError(featureName) {
|
|
|
28
16
|
+ `Please install React: npm install react`);
|
|
29
17
|
};
|
|
30
18
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Creates a class constructor that throws an error when instantiated if React is not available.
|
|
33
|
-
* Used for features like Model that need to be constructable.
|
|
34
|
-
*/
|
|
35
|
-
function createReactRequiredClass(className) {
|
|
36
|
-
return class ReactRequiredStub {
|
|
37
|
-
constructor() {
|
|
38
|
-
throw new Error(`${className} requires React to be installed. `
|
|
39
|
-
+ `Please install React: npm install react`);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
19
|
//# sourceMappingURL=reactAvailability.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactAvailability.js","sourceRoot":"","sources":["../../../src/utils/reactAvailability.ts"],"names":[],"mappings":";;AAEA,
|
|
1
|
+
{"version":3,"file":"reactAvailability.js","sourceRoot":"","sources":["../../../src/utils/reactAvailability.ts"],"names":[],"mappings":";;AAEA,4CAEC;AAMD,4DAOC;AAjBD,+DAA2D;AAE3D,SAAgB,gBAAgB;IAC9B,OAAO,IAAA,wCAAkB,EAAC,OAAO,CAAC,CAAC;AACrC,CAAC;AAED;;;GAGG;AACH,SAAgB,wBAAwB,CAAU,WAAmB;IACnE,OAAO,SAAS,iBAAiB,CAAC,GAAG,KAAY;QAC/C,MAAM,IAAI,KAAK,CACb,GAAG,WAAW,mCAAmC;cAC/C,yCAAyC,CAC5C,CAAC;IACJ,CAAM,CAAC;AACT,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reactNativeAvailability.d.ts","sourceRoot":"","sources":["../../../src/utils/reactNativeAvailability.ts"],"names":[],"mappings":"AAIA,wBAAgB,sBAAsB,IAAI,OAAO,CAQhD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isReactNativeAvailable = isReactNativeAvailable;
|
|
4
|
+
const packageAvailability_1 = require("./packageAvailability");
|
|
5
|
+
let cache;
|
|
6
|
+
function isReactNativeAvailable() {
|
|
7
|
+
if (cache !== undefined)
|
|
8
|
+
return cache;
|
|
9
|
+
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
|
|
10
|
+
cache = true;
|
|
11
|
+
return cache;
|
|
12
|
+
}
|
|
13
|
+
cache = (0, packageAvailability_1.isPackageAvailable)('react-native');
|
|
14
|
+
return cache;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=reactNativeAvailability.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reactNativeAvailability.js","sourceRoot":"","sources":["../../../src/utils/reactNativeAvailability.ts"],"names":[],"mappings":";;AAIA,wDAQC;AAZD,+DAA2D;AAE3D,IAAI,KAA0B,CAAC;AAE/B,SAAgB,sBAAsB;IACpC,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IACtC,IAAI,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,CAAC,OAAO,KAAK,aAAa,EAAE,CAAC;QAC5E,KAAK,GAAG,IAAI,CAAC;QACb,OAAO,KAAK,CAAC;IACf,CAAC;IACD,KAAK,GAAG,IAAA,wCAAkB,EAAC,cAAc,CAAC,CAAC;IAC3C,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ObjectGraph } from '../../src';
|
|
2
|
+
export declare class RetainedLifecycleBoundGraph extends ObjectGraph<Record<string, any>> {
|
|
3
|
+
static timesCreated: number;
|
|
4
|
+
constructor(props?: Record<string, any>);
|
|
5
|
+
doesNotRequireProps(): string;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=RetainedLifecycleBoundGraph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RetainedLifecycleBoundGraph.d.ts","sourceRoot":"","sources":["../../../test/fixtures/RetainedLifecycleBoundGraph.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EAGZ,MAAM,WAAW,CAAC;AAEnB,qBACa,2BAA4B,SAAQ,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC/E,MAAM,CAAC,YAAY,SAAK;gBAEZ,KAAK,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM;IAM3C,mBAAmB,IAAI,MAAM;CAG9B"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
3
|
+
var useValue = arguments.length > 2;
|
|
4
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
5
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
6
|
+
}
|
|
7
|
+
return useValue ? value : void 0;
|
|
8
|
+
};
|
|
9
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
10
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
11
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
12
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
13
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
14
|
+
var _, done = false;
|
|
15
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
16
|
+
var context = {};
|
|
17
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
18
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
19
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
20
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
21
|
+
if (kind === "accessor") {
|
|
22
|
+
if (result === void 0) continue;
|
|
23
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
24
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
25
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
26
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
27
|
+
}
|
|
28
|
+
else if (_ = accept(result)) {
|
|
29
|
+
if (kind === "field") initializers.unshift(_);
|
|
30
|
+
else descriptor[key] = _;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
34
|
+
done = true;
|
|
35
|
+
};
|
|
36
|
+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
|
37
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
38
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
39
|
+
};
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.RetainedLifecycleBoundGraph = void 0;
|
|
42
|
+
const src_1 = require("../../src");
|
|
43
|
+
let RetainedLifecycleBoundGraph = (() => {
|
|
44
|
+
let _classDecorators = [(0, src_1.lifecycleBound)({ inactiveBehavior: 'retain' }), (0, src_1.graph)()];
|
|
45
|
+
let _classDescriptor;
|
|
46
|
+
let _classExtraInitializers = [];
|
|
47
|
+
let _classThis;
|
|
48
|
+
let _classSuper = src_1.ObjectGraph;
|
|
49
|
+
let _instanceExtraInitializers = [];
|
|
50
|
+
let _doesNotRequireProps_decorators;
|
|
51
|
+
var RetainedLifecycleBoundGraph = _classThis = class extends _classSuper {
|
|
52
|
+
constructor(props = {}) {
|
|
53
|
+
super(props);
|
|
54
|
+
__runInitializers(this, _instanceExtraInitializers);
|
|
55
|
+
RetainedLifecycleBoundGraph.timesCreated++;
|
|
56
|
+
}
|
|
57
|
+
doesNotRequireProps() {
|
|
58
|
+
return 'A string that does not require props';
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
__setFunctionName(_classThis, "RetainedLifecycleBoundGraph");
|
|
62
|
+
(() => {
|
|
63
|
+
var _a;
|
|
64
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create((_a = _classSuper[Symbol.metadata]) !== null && _a !== void 0 ? _a : null) : void 0;
|
|
65
|
+
_doesNotRequireProps_decorators = [(0, src_1.provides)()];
|
|
66
|
+
__esDecorate(_classThis, null, _doesNotRequireProps_decorators, { kind: "method", name: "doesNotRequireProps", static: false, private: false, access: { has: obj => "doesNotRequireProps" in obj, get: obj => obj.doesNotRequireProps }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
67
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
68
|
+
RetainedLifecycleBoundGraph = _classThis = _classDescriptor.value;
|
|
69
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
70
|
+
})();
|
|
71
|
+
_classThis.timesCreated = 0;
|
|
72
|
+
(() => {
|
|
73
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
74
|
+
})();
|
|
75
|
+
return RetainedLifecycleBoundGraph = _classThis;
|
|
76
|
+
})();
|
|
77
|
+
exports.RetainedLifecycleBoundGraph = RetainedLifecycleBoundGraph;
|
|
78
|
+
//# sourceMappingURL=RetainedLifecycleBoundGraph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RetainedLifecycleBoundGraph.js","sourceRoot":"","sources":["../../../test/fixtures/RetainedLifecycleBoundGraph.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAKmB;IAGN,2BAA2B;4BADvC,IAAA,oBAAc,EAAC,EAAE,gBAAgB,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAA,WAAK,GAAE;;;;sBACP,iBAAW;;;wDAAnB,SAAQ,WAAgC;QAG/E,YAAY,QAA6B,EAAE;YACzC,KAAK,CAAC,KAAK,CAAC,CAAC;YAJJ,mDAA2B;YAKpC,2BAA2B,CAAC,YAAY,EAAE,CAAC;SAC5C;QAGD,mBAAmB;YACjB,OAAO,sCAAsC,CAAC;QAChD,CAAC;;;;;;2CAHA,IAAA,cAAQ,GAAE;QACX,kNAAA,mBAAmB,6DAElB;QAXH,6KAYC;;;;IAXQ,uBAAY,GAAG,CAAC,AAAJ,CAAK;;QADb,uDAA2B;;;;AAA3B,kEAA2B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-obsidian",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.31.0-alpha.1",
|
|
4
4
|
"description": "Dependency injection framework for React and React Native applications",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prepack": "yarn lint && tsc --project tsconfig.prod.json",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"@babel/preset-typescript": "7.26.0",
|
|
40
40
|
"@babel/types": "7.24.5",
|
|
41
41
|
"@stylistic/eslint-plugin": "^1.7.0",
|
|
42
|
+
"@testing-library/jest-dom": "^6.9.1",
|
|
42
43
|
"@testing-library/react": "14.x.x",
|
|
43
44
|
"@types/hoist-non-react-statics": "^3.3.1",
|
|
44
45
|
"@types/jest": "^30.0.0",
|
|
@@ -2,12 +2,14 @@ import {Reflect} from '../utils/reflect';
|
|
|
2
2
|
|
|
3
3
|
type Options = {
|
|
4
4
|
scope?: 'component' | 'feature' | (string & {});
|
|
5
|
+
inactiveBehavior?: 'unmount' | 'retain';
|
|
5
6
|
};
|
|
6
7
|
|
|
7
8
|
export function lifecycleBound(options?: Options) {
|
|
8
9
|
return (constructor: any) => {
|
|
9
10
|
Reflect.defineMetadata('isLifecycleBound', true, constructor);
|
|
10
11
|
Reflect.defineMetadata('lifecycleScope', options?.scope ?? 'feature', constructor);
|
|
12
|
+
Reflect.defineMetadata('inactiveBehavior', options?.inactiveBehavior ?? 'unmount', constructor);
|
|
11
13
|
return constructor;
|
|
12
14
|
};
|
|
13
15
|
}
|
package/src/graph/ObjectGraph.ts
CHANGED
|
@@ -10,6 +10,10 @@ import { getConstructorOrParentConstructor } from '../utils/object';
|
|
|
10
10
|
export abstract class ObjectGraph<T = unknown> implements Graph {
|
|
11
11
|
private propertyRetriever = new PropertyRetriever(this);
|
|
12
12
|
|
|
13
|
+
get inactiveBehavior(): 'unmount' | 'retain' {
|
|
14
|
+
return Reflect.getMetadata('inactiveBehavior', this.constructor) ?? 'unmount';
|
|
15
|
+
}
|
|
16
|
+
|
|
13
17
|
get name(): string {
|
|
14
18
|
const target = getConstructorOrParentConstructor(this.constructor, ObjectGraph.name);
|
|
15
19
|
if (Reflect.hasMetadata('memoizedName', target)) {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import React, { PropsWithChildren } from 'react';
|
|
1
|
+
import React, { PropsWithChildren, useRef } from 'react';
|
|
2
2
|
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
3
3
|
import { ObjectGraph } from '../../graph/ObjectGraph';
|
|
4
4
|
import PropsInjector from './PropsInjector';
|
|
5
5
|
import useGraph from './useGraph';
|
|
6
|
+
import useGraphContainer from './useGraphContainer';
|
|
6
7
|
import { Constructable } from '../../types';
|
|
7
8
|
import { genericMemo, isMemoizedComponent } from '../../utils/React';
|
|
8
9
|
import { GraphContext } from './graphContext';
|
|
@@ -28,12 +29,16 @@ export default class ComponentInjector {
|
|
|
28
29
|
|
|
29
30
|
return genericMemo((passedProps: P) => {
|
|
30
31
|
const injectionToken = useInjectionToken(keyOrGraph);
|
|
31
|
-
const
|
|
32
|
+
const containerRef = useRef(null);
|
|
33
|
+
const graph = useGraph<P>(keyOrGraph, Target, passedProps, injectionToken, containerRef);
|
|
34
|
+
const Container = useGraphContainer(graph);
|
|
32
35
|
const proxiedProps = new PropsInjector(graph).inject(passedProps);
|
|
33
36
|
|
|
34
37
|
return (
|
|
35
38
|
<GraphContext.Provider value={{injectionToken}}>
|
|
36
|
-
{
|
|
39
|
+
<Container ref={containerRef}>
|
|
40
|
+
{Target(proxiedProps as unknown as PropsWithChildren<P>)}
|
|
41
|
+
</Container>
|
|
37
42
|
</GraphContext.Provider>
|
|
38
43
|
);
|
|
39
44
|
}, compare);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
2
|
import { Constructable } from '../../types';
|
|
3
3
|
import { ObjectGraph } from '../../graph/ObjectGraph';
|
|
4
4
|
import graphRegistry from '../../graph/registry/GraphRegistry';
|
|
@@ -9,6 +9,7 @@ export default <P>(
|
|
|
9
9
|
target: any,
|
|
10
10
|
props?: Partial<P>,
|
|
11
11
|
injectionToken?: string,
|
|
12
|
+
containerRef?: React.RefObject<any>,
|
|
12
13
|
) => {
|
|
13
14
|
|
|
14
15
|
const [graph] = useState(() => {
|
|
@@ -18,7 +19,14 @@ export default <P>(
|
|
|
18
19
|
});
|
|
19
20
|
useEffect(() => {
|
|
20
21
|
referenceCounter.retain(graph);
|
|
21
|
-
return () =>
|
|
22
|
+
return () => {
|
|
23
|
+
const isCleanupCalledDueToActivityPause = containerRef?.current;
|
|
24
|
+
referenceCounter.release(graph, (g) => {
|
|
25
|
+
if (!isCleanupCalledDueToActivityPause) {
|
|
26
|
+
graphRegistry.clear(g);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
};
|
|
22
30
|
}, [graph]);
|
|
23
31
|
return graph;
|
|
24
32
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React, { forwardRef, PropsWithChildren } from 'react';
|
|
2
|
+
import { ObjectGraph } from '../../graph/ObjectGraph';
|
|
3
|
+
import { isReactNativeAvailable } from '../../utils/reactNativeAvailability';
|
|
4
|
+
|
|
5
|
+
const isRN = isReactNativeAvailable();
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports, global-require
|
|
7
|
+
const Element: any = isRN ? require('react-native').View : 'div';
|
|
8
|
+
|
|
9
|
+
const RetainContainer = forwardRef<any, PropsWithChildren>((props, ref) => (
|
|
10
|
+
<Element ref={ref} style={isRN ? undefined : { display: 'contents' }}>{props.children}</Element>
|
|
11
|
+
));
|
|
12
|
+
|
|
13
|
+
const PassthroughContainer = forwardRef<any, PropsWithChildren>((props) => (
|
|
14
|
+
<>{props.children}</>
|
|
15
|
+
));
|
|
16
|
+
|
|
17
|
+
export default function useGraphContainer(graph: ObjectGraph) {
|
|
18
|
+
return graph.inactiveBehavior === 'retain' ? RetainContainer : PassthroughContainer;
|
|
19
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const cache = new Map<string, boolean>();
|
|
2
|
+
|
|
3
|
+
export function isPackageAvailable(name: string): boolean {
|
|
4
|
+
if (cache.has(name)) return cache.get(name)!;
|
|
5
|
+
try {
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports, global-require
|
|
7
|
+
require(name);
|
|
8
|
+
cache.set(name, true);
|
|
9
|
+
} catch {
|
|
10
|
+
cache.set(name, false);
|
|
11
|
+
}
|
|
12
|
+
return cache.get(name)!;
|
|
13
|
+
}
|
|
@@ -1,19 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { isPackageAvailable } from './packageAvailability';
|
|
2
2
|
|
|
3
3
|
export function isReactAvailable(): boolean {
|
|
4
|
-
|
|
5
|
-
return reactAvailableCache;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
try {
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports, global-require
|
|
10
|
-
require('react');
|
|
11
|
-
reactAvailableCache = true;
|
|
12
|
-
} catch {
|
|
13
|
-
reactAvailableCache = false;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return reactAvailableCache;
|
|
4
|
+
return isPackageAvailable('react');
|
|
17
5
|
}
|
|
18
6
|
|
|
19
7
|
/**
|
|
@@ -28,18 +16,3 @@ export function createReactRequiredError<T = any>(featureName: string): T {
|
|
|
28
16
|
);
|
|
29
17
|
} as T;
|
|
30
18
|
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Creates a class constructor that throws an error when instantiated if React is not available.
|
|
34
|
-
* Used for features like Model that need to be constructable.
|
|
35
|
-
*/
|
|
36
|
-
export function createReactRequiredClass<T = any>(className: string): T {
|
|
37
|
-
return class ReactRequiredStub {
|
|
38
|
-
constructor() {
|
|
39
|
-
throw new Error(
|
|
40
|
-
`${className} requires React to be installed. `
|
|
41
|
-
+ `Please install React: npm install react`,
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
} as T;
|
|
45
|
-
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isPackageAvailable } from './packageAvailability';
|
|
2
|
+
|
|
3
|
+
let cache: boolean | undefined;
|
|
4
|
+
|
|
5
|
+
export function isReactNativeAvailable(): boolean {
|
|
6
|
+
if (cache !== undefined) return cache;
|
|
7
|
+
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
|
|
8
|
+
cache = true;
|
|
9
|
+
return cache;
|
|
10
|
+
}
|
|
11
|
+
cache = isPackageAvailable('react-native');
|
|
12
|
+
return cache;
|
|
13
|
+
}
|