@contember/react-binding 2.2.0-alpha.21 → 2.2.0-alpha.22
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/development/src/accessorPropagation/useAccessorUpdateSubscription.cjs +4 -2
- package/dist/development/src/accessorPropagation/useAccessorUpdateSubscription.cjs.map +1 -1
- package/dist/development/src/accessorPropagation/useAccessorUpdateSubscription.js +4 -2
- package/dist/development/src/accessorPropagation/useAccessorUpdateSubscription.js.map +1 -1
- package/dist/development/src/accessorPropagation/useEntity.cjs +2 -4
- package/dist/development/src/accessorPropagation/useEntity.cjs.map +1 -1
- package/dist/development/src/accessorPropagation/useEntity.js +2 -4
- package/dist/development/src/accessorPropagation/useEntity.js.map +1 -1
- package/dist/development/src/accessorPropagation/useEntityList.cjs +2 -4
- package/dist/development/src/accessorPropagation/useEntityList.cjs.map +1 -1
- package/dist/development/src/accessorPropagation/useEntityList.js +2 -4
- package/dist/development/src/accessorPropagation/useEntityList.js.map +1 -1
- package/dist/development/src/accessorPropagation/useField.cjs +2 -4
- package/dist/development/src/accessorPropagation/useField.cjs.map +1 -1
- package/dist/development/src/accessorPropagation/useField.js +2 -4
- package/dist/development/src/accessorPropagation/useField.js.map +1 -1
- package/dist/development/src/accessorPropagation/useOnHasOneRelationPathConnectionUpdate.cjs +33 -0
- package/dist/development/src/accessorPropagation/useOnHasOneRelationPathConnectionUpdate.cjs.map +1 -0
- package/dist/development/src/accessorPropagation/useOnHasOneRelationPathConnectionUpdate.js +33 -0
- package/dist/development/src/accessorPropagation/useOnHasOneRelationPathConnectionUpdate.js.map +1 -0
- package/dist/production/src/accessorPropagation/useAccessorUpdateSubscription.cjs +4 -2
- package/dist/production/src/accessorPropagation/useAccessorUpdateSubscription.cjs.map +1 -1
- package/dist/production/src/accessorPropagation/useAccessorUpdateSubscription.js +4 -2
- package/dist/production/src/accessorPropagation/useAccessorUpdateSubscription.js.map +1 -1
- package/dist/production/src/accessorPropagation/useEntity.cjs +2 -4
- package/dist/production/src/accessorPropagation/useEntity.cjs.map +1 -1
- package/dist/production/src/accessorPropagation/useEntity.js +2 -4
- package/dist/production/src/accessorPropagation/useEntity.js.map +1 -1
- package/dist/production/src/accessorPropagation/useEntityList.cjs +2 -4
- package/dist/production/src/accessorPropagation/useEntityList.cjs.map +1 -1
- package/dist/production/src/accessorPropagation/useEntityList.js +2 -4
- package/dist/production/src/accessorPropagation/useEntityList.js.map +1 -1
- package/dist/production/src/accessorPropagation/useField.cjs +2 -4
- package/dist/production/src/accessorPropagation/useField.cjs.map +1 -1
- package/dist/production/src/accessorPropagation/useField.js +2 -4
- package/dist/production/src/accessorPropagation/useField.js.map +1 -1
- package/dist/production/src/accessorPropagation/useOnHasOneRelationPathConnectionUpdate.cjs +33 -0
- package/dist/production/src/accessorPropagation/useOnHasOneRelationPathConnectionUpdate.cjs.map +1 -0
- package/dist/production/src/accessorPropagation/useOnHasOneRelationPathConnectionUpdate.js +33 -0
- package/dist/production/src/accessorPropagation/useOnHasOneRelationPathConnectionUpdate.js.map +1 -0
- package/dist/types/accessorPropagation/useAccessorUpdateSubscription.d.ts +1 -0
- package/dist/types/accessorPropagation/useAccessorUpdateSubscription.d.ts.map +1 -1
- package/dist/types/accessorPropagation/useEntity.d.ts.map +1 -1
- package/dist/types/accessorPropagation/useEntityList.d.ts.map +1 -1
- package/dist/types/accessorPropagation/useField.d.ts.map +1 -1
- package/dist/types/accessorPropagation/useOnHasOneRelationPathConnectionUpdate.d.ts +7 -0
- package/dist/types/accessorPropagation/useOnHasOneRelationPathConnectionUpdate.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/src/accessorPropagation/useAccessorUpdateSubscription.ts +8 -2
- package/src/accessorPropagation/useEntity.ts +2 -4
- package/src/accessorPropagation/useEntityList.ts +2 -4
- package/src/accessorPropagation/useField.ts +2 -4
- package/src/accessorPropagation/useOnHasOneRelationPathConnectionUpdate.ts +38 -0
- package/tests/cases/unit/core/nestedHasOneReconnect.test.tsx +280 -0
|
@@ -10,19 +10,21 @@ const useAccessorUpdateSubscription = (getAccessor) => {
|
|
|
10
10
|
setState(accessor);
|
|
11
11
|
getterRef.current = getAccessor;
|
|
12
12
|
}
|
|
13
|
+
const getSubscribedAccessor = accessor.getAccessor;
|
|
13
14
|
React.useEffect(() => {
|
|
14
15
|
let isStillSubscribed = true;
|
|
15
|
-
const unsubscribe =
|
|
16
|
+
const unsubscribe = getSubscribedAccessor().addEventListener({ type: "update" }, (newAccessor) => {
|
|
16
17
|
if (!isStillSubscribed || getterRef.current !== getAccessor) {
|
|
17
18
|
return;
|
|
18
19
|
}
|
|
19
20
|
setState(newAccessor);
|
|
20
21
|
});
|
|
22
|
+
setState(getAccessor());
|
|
21
23
|
return () => {
|
|
22
24
|
isStillSubscribed = false;
|
|
23
25
|
unsubscribe();
|
|
24
26
|
};
|
|
25
|
-
}, [getAccessor]);
|
|
27
|
+
}, [getAccessor, getSubscribedAccessor]);
|
|
26
28
|
const update = React.useCallback(() => {
|
|
27
29
|
setState(getAccessor());
|
|
28
30
|
}, [getAccessor]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAccessorUpdateSubscription.cjs","sources":["../../../../../packages/react-binding/src/accessorPropagation/useAccessorUpdateSubscription.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react'\n\n/**\n * It is VERY IMPORTANT for the parameter to be referentially stable!\n */\nexport const useAccessorUpdateSubscription = <\n\tAccessor extends {\n\t\taddEventListener: (event: { type: 'update' }, cb: (accessor: Accessor) => void) => () => void\n\t},\n>(getAccessor: () => Accessor): [Accessor, { update: () => void }] => {\n\tconst [state, setState] = useState<Accessor>(() => getAccessor())\n\tconst getterRef = useRef(getAccessor)\n\n\tlet accessor = state\n\tif (getterRef.current !== getAccessor) {\n\t\taccessor = getAccessor()\n\t\tsetState(accessor)\n\t\tgetterRef.current = getAccessor\n\t}\n\n\tuseEffect(() => {\n\t\tlet isStillSubscribed = true\n\t\tconst unsubscribe =
|
|
1
|
+
{"version":3,"file":"useAccessorUpdateSubscription.cjs","sources":["../../../../../packages/react-binding/src/accessorPropagation/useAccessorUpdateSubscription.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react'\n\n/**\n * It is VERY IMPORTANT for the parameter to be referentially stable!\n */\nexport const useAccessorUpdateSubscription = <\n\tAccessor extends {\n\t\taddEventListener: (event: { type: 'update' }, cb: (accessor: Accessor) => void) => () => void\n\t\tgetAccessor: () => Accessor\n\t},\n>(getAccessor: () => Accessor): [Accessor, { update: () => void }] => {\n\tconst [state, setState] = useState<Accessor>(() => getAccessor())\n\tconst getterRef = useRef(getAccessor)\n\n\tlet accessor = state\n\tif (getterRef.current !== getAccessor) {\n\t\taccessor = getAccessor()\n\t\tsetState(accessor)\n\t\tgetterRef.current = getAccessor\n\t}\n\n\t// A state node's getter is stable, so this changes exactly when `getAccessor` resolves to another node.\n\tconst getSubscribedAccessor = accessor.getAccessor\n\n\tuseEffect(() => {\n\t\tlet isStillSubscribed = true\n\t\tconst unsubscribe = getSubscribedAccessor().addEventListener({ type: 'update' }, newAccessor => {\n\t\t\tif (!isStillSubscribed || getterRef.current !== getAccessor) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tsetState(newAccessor)\n\t\t})\n\t\t// Catches up with updates that landed between the render and this subscription.\n\t\tsetState(getAccessor())\n\n\t\treturn () => {\n\t\t\tisStillSubscribed = false\n\t\t\tunsubscribe()\n\t\t}\n\t}, [getAccessor, getSubscribedAccessor])\n\n\tconst update = useCallback(() => {\n\t\tsetState(getAccessor())\n\t}, [getAccessor])\n\n\treturn [accessor, { update }]\n}\n"],"names":["useState","useRef","useEffect","useCallback"],"mappings":";;;AAKO,MAAM,gCAAgC,CAK3C,gBAAoE;AACrE,QAAM,CAAC,OAAO,QAAQ,IAAIA,MAAAA,SAAmB,MAAM,aAAa;AAChE,QAAM,YAAYC,MAAAA,OAAO,WAAW;AAEpC,MAAI,WAAW;AACf,MAAI,UAAU,YAAY,aAAa;AACtC,eAAW,YAAA;AACX,aAAS,QAAQ;AACjB,cAAU,UAAU;AAAA,EACrB;AAGA,QAAM,wBAAwB,SAAS;AAEvCC,QAAAA,UAAU,MAAM;AACf,QAAI,oBAAoB;AACxB,UAAM,cAAc,wBAAwB,iBAAiB,EAAE,MAAM,SAAA,GAAY,CAAA,gBAAe;AAC/F,UAAI,CAAC,qBAAqB,UAAU,YAAY,aAAa;AAC5D;AAAA,MACD;AACA,eAAS,WAAW;AAAA,IACrB,CAAC;AAED,aAAS,aAAa;AAEtB,WAAO,MAAM;AACZ,0BAAoB;AACpB,kBAAA;AAAA,IACD;AAAA,EACD,GAAG,CAAC,aAAa,qBAAqB,CAAC;AAEvC,QAAM,SAASC,MAAAA,YAAY,MAAM;AAChC,aAAS,aAAa;AAAA,EACvB,GAAG,CAAC,WAAW,CAAC;AAEhB,SAAO,CAAC,UAAU,EAAE,QAAQ;AAC7B;;"}
|
|
@@ -8,19 +8,21 @@ const useAccessorUpdateSubscription = (getAccessor) => {
|
|
|
8
8
|
setState(accessor);
|
|
9
9
|
getterRef.current = getAccessor;
|
|
10
10
|
}
|
|
11
|
+
const getSubscribedAccessor = accessor.getAccessor;
|
|
11
12
|
useEffect(() => {
|
|
12
13
|
let isStillSubscribed = true;
|
|
13
|
-
const unsubscribe =
|
|
14
|
+
const unsubscribe = getSubscribedAccessor().addEventListener({ type: "update" }, (newAccessor) => {
|
|
14
15
|
if (!isStillSubscribed || getterRef.current !== getAccessor) {
|
|
15
16
|
return;
|
|
16
17
|
}
|
|
17
18
|
setState(newAccessor);
|
|
18
19
|
});
|
|
20
|
+
setState(getAccessor());
|
|
19
21
|
return () => {
|
|
20
22
|
isStillSubscribed = false;
|
|
21
23
|
unsubscribe();
|
|
22
24
|
};
|
|
23
|
-
}, [getAccessor]);
|
|
25
|
+
}, [getAccessor, getSubscribedAccessor]);
|
|
24
26
|
const update = useCallback(() => {
|
|
25
27
|
setState(getAccessor());
|
|
26
28
|
}, [getAccessor]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAccessorUpdateSubscription.js","sources":["../../../../../packages/react-binding/src/accessorPropagation/useAccessorUpdateSubscription.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react'\n\n/**\n * It is VERY IMPORTANT for the parameter to be referentially stable!\n */\nexport const useAccessorUpdateSubscription = <\n\tAccessor extends {\n\t\taddEventListener: (event: { type: 'update' }, cb: (accessor: Accessor) => void) => () => void\n\t},\n>(getAccessor: () => Accessor): [Accessor, { update: () => void }] => {\n\tconst [state, setState] = useState<Accessor>(() => getAccessor())\n\tconst getterRef = useRef(getAccessor)\n\n\tlet accessor = state\n\tif (getterRef.current !== getAccessor) {\n\t\taccessor = getAccessor()\n\t\tsetState(accessor)\n\t\tgetterRef.current = getAccessor\n\t}\n\n\tuseEffect(() => {\n\t\tlet isStillSubscribed = true\n\t\tconst unsubscribe =
|
|
1
|
+
{"version":3,"file":"useAccessorUpdateSubscription.js","sources":["../../../../../packages/react-binding/src/accessorPropagation/useAccessorUpdateSubscription.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react'\n\n/**\n * It is VERY IMPORTANT for the parameter to be referentially stable!\n */\nexport const useAccessorUpdateSubscription = <\n\tAccessor extends {\n\t\taddEventListener: (event: { type: 'update' }, cb: (accessor: Accessor) => void) => () => void\n\t\tgetAccessor: () => Accessor\n\t},\n>(getAccessor: () => Accessor): [Accessor, { update: () => void }] => {\n\tconst [state, setState] = useState<Accessor>(() => getAccessor())\n\tconst getterRef = useRef(getAccessor)\n\n\tlet accessor = state\n\tif (getterRef.current !== getAccessor) {\n\t\taccessor = getAccessor()\n\t\tsetState(accessor)\n\t\tgetterRef.current = getAccessor\n\t}\n\n\t// A state node's getter is stable, so this changes exactly when `getAccessor` resolves to another node.\n\tconst getSubscribedAccessor = accessor.getAccessor\n\n\tuseEffect(() => {\n\t\tlet isStillSubscribed = true\n\t\tconst unsubscribe = getSubscribedAccessor().addEventListener({ type: 'update' }, newAccessor => {\n\t\t\tif (!isStillSubscribed || getterRef.current !== getAccessor) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tsetState(newAccessor)\n\t\t})\n\t\t// Catches up with updates that landed between the render and this subscription.\n\t\tsetState(getAccessor())\n\n\t\treturn () => {\n\t\t\tisStillSubscribed = false\n\t\t\tunsubscribe()\n\t\t}\n\t}, [getAccessor, getSubscribedAccessor])\n\n\tconst update = useCallback(() => {\n\t\tsetState(getAccessor())\n\t}, [getAccessor])\n\n\treturn [accessor, { update }]\n}\n"],"names":[],"mappings":";AAKO,MAAM,gCAAgC,CAK3C,gBAAoE;AACrE,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAmB,MAAM,aAAa;AAChE,QAAM,YAAY,OAAO,WAAW;AAEpC,MAAI,WAAW;AACf,MAAI,UAAU,YAAY,aAAa;AACtC,eAAW,YAAA;AACX,aAAS,QAAQ;AACjB,cAAU,UAAU;AAAA,EACrB;AAGA,QAAM,wBAAwB,SAAS;AAEvC,YAAU,MAAM;AACf,QAAI,oBAAoB;AACxB,UAAM,cAAc,wBAAwB,iBAAiB,EAAE,MAAM,SAAA,GAAY,CAAA,gBAAe;AAC/F,UAAI,CAAC,qBAAqB,UAAU,YAAY,aAAa;AAC5D;AAAA,MACD;AACA,eAAS,WAAW;AAAA,IACrB,CAAC;AAED,aAAS,aAAa;AAEtB,WAAO,MAAM;AACZ,0BAAoB;AACpB,kBAAA;AAAA,IACD;AAAA,EACD,GAAG,CAAC,aAAa,qBAAqB,CAAC;AAEvC,QAAM,SAAS,YAAY,MAAM;AAChC,aAAS,aAAa;AAAA,EACvB,GAAG,CAAC,WAAW,CAAC;AAEhB,SAAO,CAAC,UAAU,EAAE,QAAQ;AAC7B;"}
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const reactUtils = require("@contember/react-utils");
|
|
4
4
|
const React = require("react");
|
|
5
5
|
const useAccessorUpdateSubscription = require("./useAccessorUpdateSubscription.cjs");
|
|
6
|
+
const useOnHasOneRelationPathConnectionUpdate = require("./useOnHasOneRelationPathConnectionUpdate.cjs");
|
|
6
7
|
const useDesugaredRelativeSingleEntity = require("./useDesugaredRelativeSingleEntity.cjs");
|
|
7
|
-
const useOnConnectionUpdate = require("../entityEvents/useOnConnectionUpdate.cjs");
|
|
8
8
|
const useEntityKey = require("./useEntityKey.cjs");
|
|
9
9
|
const useGetEntityByKey = require("./useGetEntityByKey.cjs");
|
|
10
10
|
function useEntity(...entity) {
|
|
@@ -27,9 +27,7 @@ function useEntity(...entity) {
|
|
|
27
27
|
"Cannot change the length of the hasOneRelation path!"
|
|
28
28
|
);
|
|
29
29
|
const [entity2, { update }] = useAccessorUpdateSubscription.useAccessorUpdateSubscription(getEntity);
|
|
30
|
-
|
|
31
|
-
useOnConnectionUpdate.useOnConnectionUpdate(relativeSingleEntity.hasOneRelationPath[0].field, update);
|
|
32
|
-
}
|
|
30
|
+
useOnHasOneRelationPathConnectionUpdate.useOnHasOneRelationPathConnectionUpdate(relativeSingleEntity.hasOneRelationPath, update);
|
|
33
31
|
return entity2;
|
|
34
32
|
}
|
|
35
33
|
return void 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEntity.cjs","sources":["../../../../../packages/react-binding/src/accessorPropagation/useEntity.ts"],"sourcesContent":["import { useConstantLengthInvariant, useConstantValueInvariant } from '@contember/react-utils'\nimport { useCallback } from 'react'\nimport { useEntityKey, useGetEntityByKey } from './index.js'\nimport type { EntityAccessor } from '@contember/binding'\nimport {
|
|
1
|
+
{"version":3,"file":"useEntity.cjs","sources":["../../../../../packages/react-binding/src/accessorPropagation/useEntity.ts"],"sourcesContent":["import { useConstantLengthInvariant, useConstantValueInvariant } from '@contember/react-utils'\nimport { useCallback } from 'react'\nimport { useEntityKey, useGetEntityByKey } from './index.js'\nimport type { EntityAccessor } from '@contember/binding'\nimport type { SugaredRelativeSingleEntity } from '@contember/binding'\nimport { useAccessorUpdateSubscription } from './useAccessorUpdateSubscription.js'\nimport { useOnHasOneRelationPathConnectionUpdate } from './useOnHasOneRelationPathConnectionUpdate.js'\nimport { useDesugaredRelativeSingleEntity } from './useDesugaredRelativeSingleEntity.js'\n\nfunction useEntity(): EntityAccessor\nfunction useEntity(sugaredRelativeSingleEntity: string | SugaredRelativeSingleEntity): EntityAccessor\nfunction useEntity(\n\tsugaredRelativeSingleEntity: string | SugaredRelativeSingleEntity | undefined,\n): EntityAccessor | undefined\nfunction useEntity(...entity: [] | [string | SugaredRelativeSingleEntity | undefined]): EntityAccessor | undefined {\n\tuseConstantValueInvariant(entity.length, 'useEntity: cannot alternate between providing and omitting the argument.')\n\n\tconst entityKey = useEntityKey()\n\tconst getEntityByKey = useGetEntityByKey()\n\n\tif (entity.length === 0) {\n\t\tconst getEntityAccessor = useCallback(() => getEntityByKey(entityKey), [entityKey, getEntityByKey])\n\t\treturn useAccessorUpdateSubscription(getEntityAccessor)[0]\n\t}\n\tconst sugaredRelativeSingleEntity = entity[0]\n\n\tconst relativeSingleEntity = useDesugaredRelativeSingleEntity(sugaredRelativeSingleEntity)\n\tconst getEntity = useCallback(() => {\n\t\tconst parent = getEntityByKey(entityKey)\n\t\treturn parent.getEntity(relativeSingleEntity!)\n\t}, [entityKey, getEntityByKey, relativeSingleEntity])\n\n\tif (relativeSingleEntity) {\n\t\tuseConstantLengthInvariant(\n\t\t\trelativeSingleEntity.hasOneRelationPath,\n\t\t\t'Cannot change the length of the hasOneRelation path!',\n\t\t)\n\t\tconst [entity, { update }] = useAccessorUpdateSubscription(getEntity)\n\n\t\tuseOnHasOneRelationPathConnectionUpdate(relativeSingleEntity.hasOneRelationPath, update)\n\n\t\treturn entity\n\t}\n\treturn undefined\n}\n\nexport { useEntity }\n"],"names":["useConstantValueInvariant","useEntityKey","useGetEntityByKey","useCallback","useAccessorUpdateSubscription","useDesugaredRelativeSingleEntity","useConstantLengthInvariant","entity","useOnHasOneRelationPathConnectionUpdate"],"mappings":";;;;;;;;;AAcA,SAAS,aAAa,QAA6F;AAClHA,uCAA0B,OAAO,QAAQ,0EAA0E;AAEnH,QAAM,YAAYC,aAAAA,aAAA;AAClB,QAAM,iBAAiBC,kBAAAA,kBAAA;AAEvB,MAAI,OAAO,WAAW,GAAG;AACxB,UAAM,oBAAoBC,MAAAA,YAAY,MAAM,eAAe,SAAS,GAAG,CAAC,WAAW,cAAc,CAAC;AAClG,WAAOC,8BAAAA,8BAA8B,iBAAiB,EAAE,CAAC;AAAA,EAC1D;AACA,QAAM,8BAA8B,OAAO,CAAC;AAE5C,QAAM,uBAAuBC,iCAAAA,iCAAiC,2BAA2B;AACzF,QAAM,YAAYF,MAAAA,YAAY,MAAM;AACnC,UAAM,SAAS,eAAe,SAAS;AACvC,WAAO,OAAO,UAAU,oBAAqB;AAAA,EAC9C,GAAG,CAAC,WAAW,gBAAgB,oBAAoB,CAAC;AAEpD,MAAI,sBAAsB;AACzBG,eAAAA;AAAAA,MACC,qBAAqB;AAAA,MACrB;AAAA,IAAA;AAED,UAAM,CAACC,SAAQ,EAAE,QAAQ,IAAIH,8BAAAA,8BAA8B,SAAS;AAEpEI,oFAAwC,qBAAqB,oBAAoB,MAAM;AAEvF,WAAOD;AAAAA,EACR;AACA,SAAO;AACR;;"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useConstantValueInvariant, useConstantLengthInvariant } from "@contember/react-utils";
|
|
2
2
|
import { useCallback } from "react";
|
|
3
3
|
import { useAccessorUpdateSubscription } from "./useAccessorUpdateSubscription.js";
|
|
4
|
+
import { useOnHasOneRelationPathConnectionUpdate } from "./useOnHasOneRelationPathConnectionUpdate.js";
|
|
4
5
|
import { useDesugaredRelativeSingleEntity } from "./useDesugaredRelativeSingleEntity.js";
|
|
5
|
-
import { useOnConnectionUpdate } from "../entityEvents/useOnConnectionUpdate.js";
|
|
6
6
|
import { useEntityKey } from "./useEntityKey.js";
|
|
7
7
|
import { useGetEntityByKey } from "./useGetEntityByKey.js";
|
|
8
8
|
function useEntity(...entity) {
|
|
@@ -25,9 +25,7 @@ function useEntity(...entity) {
|
|
|
25
25
|
"Cannot change the length of the hasOneRelation path!"
|
|
26
26
|
);
|
|
27
27
|
const [entity2, { update }] = useAccessorUpdateSubscription(getEntity);
|
|
28
|
-
|
|
29
|
-
useOnConnectionUpdate(relativeSingleEntity.hasOneRelationPath[0].field, update);
|
|
30
|
-
}
|
|
28
|
+
useOnHasOneRelationPathConnectionUpdate(relativeSingleEntity.hasOneRelationPath, update);
|
|
31
29
|
return entity2;
|
|
32
30
|
}
|
|
33
31
|
return void 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEntity.js","sources":["../../../../../packages/react-binding/src/accessorPropagation/useEntity.ts"],"sourcesContent":["import { useConstantLengthInvariant, useConstantValueInvariant } from '@contember/react-utils'\nimport { useCallback } from 'react'\nimport { useEntityKey, useGetEntityByKey } from './index.js'\nimport type { EntityAccessor } from '@contember/binding'\nimport {
|
|
1
|
+
{"version":3,"file":"useEntity.js","sources":["../../../../../packages/react-binding/src/accessorPropagation/useEntity.ts"],"sourcesContent":["import { useConstantLengthInvariant, useConstantValueInvariant } from '@contember/react-utils'\nimport { useCallback } from 'react'\nimport { useEntityKey, useGetEntityByKey } from './index.js'\nimport type { EntityAccessor } from '@contember/binding'\nimport type { SugaredRelativeSingleEntity } from '@contember/binding'\nimport { useAccessorUpdateSubscription } from './useAccessorUpdateSubscription.js'\nimport { useOnHasOneRelationPathConnectionUpdate } from './useOnHasOneRelationPathConnectionUpdate.js'\nimport { useDesugaredRelativeSingleEntity } from './useDesugaredRelativeSingleEntity.js'\n\nfunction useEntity(): EntityAccessor\nfunction useEntity(sugaredRelativeSingleEntity: string | SugaredRelativeSingleEntity): EntityAccessor\nfunction useEntity(\n\tsugaredRelativeSingleEntity: string | SugaredRelativeSingleEntity | undefined,\n): EntityAccessor | undefined\nfunction useEntity(...entity: [] | [string | SugaredRelativeSingleEntity | undefined]): EntityAccessor | undefined {\n\tuseConstantValueInvariant(entity.length, 'useEntity: cannot alternate between providing and omitting the argument.')\n\n\tconst entityKey = useEntityKey()\n\tconst getEntityByKey = useGetEntityByKey()\n\n\tif (entity.length === 0) {\n\t\tconst getEntityAccessor = useCallback(() => getEntityByKey(entityKey), [entityKey, getEntityByKey])\n\t\treturn useAccessorUpdateSubscription(getEntityAccessor)[0]\n\t}\n\tconst sugaredRelativeSingleEntity = entity[0]\n\n\tconst relativeSingleEntity = useDesugaredRelativeSingleEntity(sugaredRelativeSingleEntity)\n\tconst getEntity = useCallback(() => {\n\t\tconst parent = getEntityByKey(entityKey)\n\t\treturn parent.getEntity(relativeSingleEntity!)\n\t}, [entityKey, getEntityByKey, relativeSingleEntity])\n\n\tif (relativeSingleEntity) {\n\t\tuseConstantLengthInvariant(\n\t\t\trelativeSingleEntity.hasOneRelationPath,\n\t\t\t'Cannot change the length of the hasOneRelation path!',\n\t\t)\n\t\tconst [entity, { update }] = useAccessorUpdateSubscription(getEntity)\n\n\t\tuseOnHasOneRelationPathConnectionUpdate(relativeSingleEntity.hasOneRelationPath, update)\n\n\t\treturn entity\n\t}\n\treturn undefined\n}\n\nexport { useEntity }\n"],"names":["entity"],"mappings":";;;;;;;AAcA,SAAS,aAAa,QAA6F;AAClH,4BAA0B,OAAO,QAAQ,0EAA0E;AAEnH,QAAM,YAAY,aAAA;AAClB,QAAM,iBAAiB,kBAAA;AAEvB,MAAI,OAAO,WAAW,GAAG;AACxB,UAAM,oBAAoB,YAAY,MAAM,eAAe,SAAS,GAAG,CAAC,WAAW,cAAc,CAAC;AAClG,WAAO,8BAA8B,iBAAiB,EAAE,CAAC;AAAA,EAC1D;AACA,QAAM,8BAA8B,OAAO,CAAC;AAE5C,QAAM,uBAAuB,iCAAiC,2BAA2B;AACzF,QAAM,YAAY,YAAY,MAAM;AACnC,UAAM,SAAS,eAAe,SAAS;AACvC,WAAO,OAAO,UAAU,oBAAqB;AAAA,EAC9C,GAAG,CAAC,WAAW,gBAAgB,oBAAoB,CAAC;AAEpD,MAAI,sBAAsB;AACzB;AAAA,MACC,qBAAqB;AAAA,MACrB;AAAA,IAAA;AAED,UAAM,CAACA,SAAQ,EAAE,QAAQ,IAAI,8BAA8B,SAAS;AAEpE,4CAAwC,qBAAqB,oBAAoB,MAAM;AAEvF,WAAOA;AAAAA,EACR;AACA,SAAO;AACR;"}
|
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const reactUtils = require("@contember/react-utils");
|
|
4
4
|
const React = require("react");
|
|
5
5
|
const useAccessorUpdateSubscription = require("./useAccessorUpdateSubscription.cjs");
|
|
6
|
+
const useOnHasOneRelationPathConnectionUpdate = require("./useOnHasOneRelationPathConnectionUpdate.cjs");
|
|
6
7
|
const useDesugaredRelativeEntityList = require("./useDesugaredRelativeEntityList.cjs");
|
|
7
8
|
const useEntityKey = require("./useEntityKey.cjs");
|
|
8
9
|
const useGetEntityByKey = require("./useGetEntityByKey.cjs");
|
|
9
|
-
const useOnConnectionUpdate = require("../entityEvents/useOnConnectionUpdate.cjs");
|
|
10
10
|
function useEntityList(sugaredRelativeEntityList) {
|
|
11
11
|
const relativeEntityList = useDesugaredRelativeEntityList.useDesugaredRelativeEntityList(sugaredRelativeEntityList);
|
|
12
12
|
reactUtils.useConstantValueInvariant(
|
|
@@ -25,9 +25,7 @@ function useEntityList(sugaredRelativeEntityList) {
|
|
|
25
25
|
"Cannot change the length of the hasOneRelation path!"
|
|
26
26
|
);
|
|
27
27
|
const [entityList, { update }] = useAccessorUpdateSubscription.useAccessorUpdateSubscription(getEntityList);
|
|
28
|
-
|
|
29
|
-
useOnConnectionUpdate.useOnConnectionUpdate(relativeEntityList.hasOneRelationPath[0].field, update);
|
|
30
|
-
}
|
|
28
|
+
useOnHasOneRelationPathConnectionUpdate.useOnHasOneRelationPathConnectionUpdate(relativeEntityList.hasOneRelationPath, update);
|
|
31
29
|
return entityList;
|
|
32
30
|
}
|
|
33
31
|
return void 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEntityList.cjs","sources":["../../../../../packages/react-binding/src/accessorPropagation/useEntityList.ts"],"sourcesContent":["import { useConstantLengthInvariant, useConstantValueInvariant } from '@contember/react-utils'\nimport { useCallback } from 'react'\nimport { useEntityKey, useGetEntityByKey } from './index.js'\nimport type { EntityListAccessor } from '@contember/binding'\nimport {
|
|
1
|
+
{"version":3,"file":"useEntityList.cjs","sources":["../../../../../packages/react-binding/src/accessorPropagation/useEntityList.ts"],"sourcesContent":["import { useConstantLengthInvariant, useConstantValueInvariant } from '@contember/react-utils'\nimport { useCallback } from 'react'\nimport { useEntityKey, useGetEntityByKey } from './index.js'\nimport type { EntityListAccessor } from '@contember/binding'\nimport type { SugaredRelativeEntityList } from '@contember/binding'\nimport { useAccessorUpdateSubscription } from './useAccessorUpdateSubscription.js'\nimport { useOnHasOneRelationPathConnectionUpdate } from './useOnHasOneRelationPathConnectionUpdate.js'\nimport { useDesugaredRelativeEntityList } from './useDesugaredRelativeEntityList.js'\n\nfunction useEntityList(sugaredRelativeEntityList: string | SugaredRelativeEntityList): EntityListAccessor\nfunction useEntityList(\n\tsugaredRelativeEntityList: string | SugaredRelativeEntityList | undefined,\n): EntityListAccessor | undefined\nfunction useEntityList(\n\tsugaredRelativeEntityList: string | SugaredRelativeEntityList | undefined,\n): EntityListAccessor | undefined {\n\tconst relativeEntityList = useDesugaredRelativeEntityList(sugaredRelativeEntityList)\n\tuseConstantValueInvariant(\n\t\t!!relativeEntityList,\n\t\t'useEntityList: cannot alternate between providing and omitting the argument.',\n\t)\n\n\tconst entityKey = useEntityKey()\n\tconst getEntityByKey = useGetEntityByKey()\n\tconst getEntityList = useCallback(() => {\n\t\tconst parent = getEntityByKey(entityKey)\n\t\treturn parent.getEntityList(relativeEntityList!)\n\t}, [entityKey, getEntityByKey, relativeEntityList])\n\n\tif (relativeEntityList) {\n\t\tuseConstantLengthInvariant(\n\t\t\trelativeEntityList.hasOneRelationPath,\n\t\t\t'Cannot change the length of the hasOneRelation path!',\n\t\t)\n\t\tconst [entityList, { update }] = useAccessorUpdateSubscription(getEntityList)\n\n\t\tuseOnHasOneRelationPathConnectionUpdate(relativeEntityList.hasOneRelationPath, update)\n\n\t\treturn entityList\n\t}\n\treturn undefined\n}\n\nexport { useEntityList }\n"],"names":["useDesugaredRelativeEntityList","useConstantValueInvariant","useEntityKey","useGetEntityByKey","useCallback","useConstantLengthInvariant","useAccessorUpdateSubscription","useOnHasOneRelationPathConnectionUpdate"],"mappings":";;;;;;;;;AAaA,SAAS,cACR,2BACiC;AACjC,QAAM,qBAAqBA,+BAAAA,+BAA+B,yBAAyB;AACnFC,aAAAA;AAAAA,IACC,CAAC,CAAC;AAAA,IACF;AAAA,EAAA;AAGD,QAAM,YAAYC,aAAAA,aAAA;AAClB,QAAM,iBAAiBC,kBAAAA,kBAAA;AACvB,QAAM,gBAAgBC,MAAAA,YAAY,MAAM;AACvC,UAAM,SAAS,eAAe,SAAS;AACvC,WAAO,OAAO,cAAc,kBAAmB;AAAA,EAChD,GAAG,CAAC,WAAW,gBAAgB,kBAAkB,CAAC;AAElD,MAAI,oBAAoB;AACvBC,eAAAA;AAAAA,MACC,mBAAmB;AAAA,MACnB;AAAA,IAAA;AAED,UAAM,CAAC,YAAY,EAAE,QAAQ,IAAIC,8BAAAA,8BAA8B,aAAa;AAE5EC,oFAAwC,mBAAmB,oBAAoB,MAAM;AAErF,WAAO;AAAA,EACR;AACA,SAAO;AACR;;"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { useConstantValueInvariant, useConstantLengthInvariant } from "@contember/react-utils";
|
|
2
2
|
import { useCallback } from "react";
|
|
3
3
|
import { useAccessorUpdateSubscription } from "./useAccessorUpdateSubscription.js";
|
|
4
|
+
import { useOnHasOneRelationPathConnectionUpdate } from "./useOnHasOneRelationPathConnectionUpdate.js";
|
|
4
5
|
import { useDesugaredRelativeEntityList } from "./useDesugaredRelativeEntityList.js";
|
|
5
6
|
import { useEntityKey } from "./useEntityKey.js";
|
|
6
7
|
import { useGetEntityByKey } from "./useGetEntityByKey.js";
|
|
7
|
-
import { useOnConnectionUpdate } from "../entityEvents/useOnConnectionUpdate.js";
|
|
8
8
|
function useEntityList(sugaredRelativeEntityList) {
|
|
9
9
|
const relativeEntityList = useDesugaredRelativeEntityList(sugaredRelativeEntityList);
|
|
10
10
|
useConstantValueInvariant(
|
|
@@ -23,9 +23,7 @@ function useEntityList(sugaredRelativeEntityList) {
|
|
|
23
23
|
"Cannot change the length of the hasOneRelation path!"
|
|
24
24
|
);
|
|
25
25
|
const [entityList, { update }] = useAccessorUpdateSubscription(getEntityList);
|
|
26
|
-
|
|
27
|
-
useOnConnectionUpdate(relativeEntityList.hasOneRelationPath[0].field, update);
|
|
28
|
-
}
|
|
26
|
+
useOnHasOneRelationPathConnectionUpdate(relativeEntityList.hasOneRelationPath, update);
|
|
29
27
|
return entityList;
|
|
30
28
|
}
|
|
31
29
|
return void 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEntityList.js","sources":["../../../../../packages/react-binding/src/accessorPropagation/useEntityList.ts"],"sourcesContent":["import { useConstantLengthInvariant, useConstantValueInvariant } from '@contember/react-utils'\nimport { useCallback } from 'react'\nimport { useEntityKey, useGetEntityByKey } from './index.js'\nimport type { EntityListAccessor } from '@contember/binding'\nimport {
|
|
1
|
+
{"version":3,"file":"useEntityList.js","sources":["../../../../../packages/react-binding/src/accessorPropagation/useEntityList.ts"],"sourcesContent":["import { useConstantLengthInvariant, useConstantValueInvariant } from '@contember/react-utils'\nimport { useCallback } from 'react'\nimport { useEntityKey, useGetEntityByKey } from './index.js'\nimport type { EntityListAccessor } from '@contember/binding'\nimport type { SugaredRelativeEntityList } from '@contember/binding'\nimport { useAccessorUpdateSubscription } from './useAccessorUpdateSubscription.js'\nimport { useOnHasOneRelationPathConnectionUpdate } from './useOnHasOneRelationPathConnectionUpdate.js'\nimport { useDesugaredRelativeEntityList } from './useDesugaredRelativeEntityList.js'\n\nfunction useEntityList(sugaredRelativeEntityList: string | SugaredRelativeEntityList): EntityListAccessor\nfunction useEntityList(\n\tsugaredRelativeEntityList: string | SugaredRelativeEntityList | undefined,\n): EntityListAccessor | undefined\nfunction useEntityList(\n\tsugaredRelativeEntityList: string | SugaredRelativeEntityList | undefined,\n): EntityListAccessor | undefined {\n\tconst relativeEntityList = useDesugaredRelativeEntityList(sugaredRelativeEntityList)\n\tuseConstantValueInvariant(\n\t\t!!relativeEntityList,\n\t\t'useEntityList: cannot alternate between providing and omitting the argument.',\n\t)\n\n\tconst entityKey = useEntityKey()\n\tconst getEntityByKey = useGetEntityByKey()\n\tconst getEntityList = useCallback(() => {\n\t\tconst parent = getEntityByKey(entityKey)\n\t\treturn parent.getEntityList(relativeEntityList!)\n\t}, [entityKey, getEntityByKey, relativeEntityList])\n\n\tif (relativeEntityList) {\n\t\tuseConstantLengthInvariant(\n\t\t\trelativeEntityList.hasOneRelationPath,\n\t\t\t'Cannot change the length of the hasOneRelation path!',\n\t\t)\n\t\tconst [entityList, { update }] = useAccessorUpdateSubscription(getEntityList)\n\n\t\tuseOnHasOneRelationPathConnectionUpdate(relativeEntityList.hasOneRelationPath, update)\n\n\t\treturn entityList\n\t}\n\treturn undefined\n}\n\nexport { useEntityList }\n"],"names":[],"mappings":";;;;;;;AAaA,SAAS,cACR,2BACiC;AACjC,QAAM,qBAAqB,+BAA+B,yBAAyB;AACnF;AAAA,IACC,CAAC,CAAC;AAAA,IACF;AAAA,EAAA;AAGD,QAAM,YAAY,aAAA;AAClB,QAAM,iBAAiB,kBAAA;AACvB,QAAM,gBAAgB,YAAY,MAAM;AACvC,UAAM,SAAS,eAAe,SAAS;AACvC,WAAO,OAAO,cAAc,kBAAmB;AAAA,EAChD,GAAG,CAAC,WAAW,gBAAgB,kBAAkB,CAAC;AAElD,MAAI,oBAAoB;AACvB;AAAA,MACC,mBAAmB;AAAA,MACnB;AAAA,IAAA;AAED,UAAM,CAAC,YAAY,EAAE,QAAQ,IAAI,8BAA8B,aAAa;AAE5E,4CAAwC,mBAAmB,oBAAoB,MAAM;AAErF,WAAO;AAAA,EACR;AACA,SAAO;AACR;"}
|
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const reactUtils = require("@contember/react-utils");
|
|
4
4
|
const React = require("react");
|
|
5
5
|
const useAccessorUpdateSubscription = require("./useAccessorUpdateSubscription.cjs");
|
|
6
|
+
const useOnHasOneRelationPathConnectionUpdate = require("./useOnHasOneRelationPathConnectionUpdate.cjs");
|
|
6
7
|
const useDesugaredRelativeSingleField = require("./useDesugaredRelativeSingleField.cjs");
|
|
7
8
|
const useEntityKey = require("./useEntityKey.cjs");
|
|
8
9
|
const useGetEntityByKey = require("./useGetEntityByKey.cjs");
|
|
9
|
-
const useOnConnectionUpdate = require("../entityEvents/useOnConnectionUpdate.cjs");
|
|
10
10
|
function useField(sugaredRelativeSingleField) {
|
|
11
11
|
const relativeSingleField = useDesugaredRelativeSingleField.useDesugaredRelativeSingleField(sugaredRelativeSingleField);
|
|
12
12
|
reactUtils.useConstantValueInvariant(
|
|
@@ -25,9 +25,7 @@ function useField(sugaredRelativeSingleField) {
|
|
|
25
25
|
"Cannot change the length of the hasOneRelation path!"
|
|
26
26
|
);
|
|
27
27
|
const [field, { update }] = useAccessorUpdateSubscription.useAccessorUpdateSubscription(getField);
|
|
28
|
-
|
|
29
|
-
useOnConnectionUpdate.useOnConnectionUpdate(relativeSingleField.hasOneRelationPath[0].field, update);
|
|
30
|
-
}
|
|
28
|
+
useOnHasOneRelationPathConnectionUpdate.useOnHasOneRelationPathConnectionUpdate(relativeSingleField.hasOneRelationPath, update);
|
|
31
29
|
return field;
|
|
32
30
|
}
|
|
33
31
|
return void 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useField.cjs","sources":["../../../../../packages/react-binding/src/accessorPropagation/useField.ts"],"sourcesContent":["import { useConstantLengthInvariant, useConstantValueInvariant } from '@contember/react-utils'\nimport { useCallback } from 'react'\nimport { useEntityKey, useGetEntityByKey } from './index.js'\nimport type { FieldAccessor } from '@contember/binding'\nimport {
|
|
1
|
+
{"version":3,"file":"useField.cjs","sources":["../../../../../packages/react-binding/src/accessorPropagation/useField.ts"],"sourcesContent":["import { useConstantLengthInvariant, useConstantValueInvariant } from '@contember/react-utils'\nimport { useCallback } from 'react'\nimport { useEntityKey, useGetEntityByKey } from './index.js'\nimport type { FieldAccessor } from '@contember/binding'\nimport type { FieldValue, SugaredRelativeSingleField } from '@contember/binding'\nimport { useAccessorUpdateSubscription } from './useAccessorUpdateSubscription.js'\nimport { useOnHasOneRelationPathConnectionUpdate } from './useOnHasOneRelationPathConnectionUpdate.js'\nimport { useDesugaredRelativeSingleField } from './useDesugaredRelativeSingleField.js'\n\nfunction useField<Value extends FieldValue = FieldValue>(\n\tsugaredRelativeSingleField: string | SugaredRelativeSingleField,\n): FieldAccessor<Value>\nfunction useField<Value extends FieldValue = FieldValue>(\n\tsugaredRelativeSingleField: string | SugaredRelativeSingleField | undefined,\n): FieldAccessor<Value> | undefined\nfunction useField<Value extends FieldValue = FieldValue>(\n\tsugaredRelativeSingleField: string | SugaredRelativeSingleField | undefined,\n): FieldAccessor<Value> | undefined {\n\tconst relativeSingleField = useDesugaredRelativeSingleField(sugaredRelativeSingleField)\n\tuseConstantValueInvariant(\n\t\t!!relativeSingleField,\n\t\t'useField: cannot alternate between providing and omitting the argument.',\n\t)\n\n\tconst entityKey = useEntityKey()\n\tconst getEntityByKey = useGetEntityByKey()\n\tconst getField = useCallback(() => {\n\t\tconst parent = getEntityByKey(entityKey)\n\t\treturn parent.getField<Value>(relativeSingleField!)\n\t}, [entityKey, getEntityByKey, relativeSingleField])\n\n\tif (relativeSingleField) {\n\t\tuseConstantLengthInvariant(\n\t\t\trelativeSingleField.hasOneRelationPath,\n\t\t\t'Cannot change the length of the hasOneRelation path!',\n\t\t)\n\t\tconst [field, { update }] = useAccessorUpdateSubscription(getField)\n\n\t\tuseOnHasOneRelationPathConnectionUpdate(relativeSingleField.hasOneRelationPath, update)\n\n\t\treturn field\n\t}\n\treturn undefined\n}\n\nexport { useField }\n"],"names":["useDesugaredRelativeSingleField","useConstantValueInvariant","useEntityKey","useGetEntityByKey","useCallback","useConstantLengthInvariant","useAccessorUpdateSubscription","useOnHasOneRelationPathConnectionUpdate"],"mappings":";;;;;;;;;AAeA,SAAS,SACR,4BACmC;AACnC,QAAM,sBAAsBA,gCAAAA,gCAAgC,0BAA0B;AACtFC,aAAAA;AAAAA,IACC,CAAC,CAAC;AAAA,IACF;AAAA,EAAA;AAGD,QAAM,YAAYC,aAAAA,aAAA;AAClB,QAAM,iBAAiBC,kBAAAA,kBAAA;AACvB,QAAM,WAAWC,MAAAA,YAAY,MAAM;AAClC,UAAM,SAAS,eAAe,SAAS;AACvC,WAAO,OAAO,SAAgB,mBAAoB;AAAA,EACnD,GAAG,CAAC,WAAW,gBAAgB,mBAAmB,CAAC;AAEnD,MAAI,qBAAqB;AACxBC,eAAAA;AAAAA,MACC,oBAAoB;AAAA,MACpB;AAAA,IAAA;AAED,UAAM,CAAC,OAAO,EAAE,QAAQ,IAAIC,8BAAAA,8BAA8B,QAAQ;AAElEC,oFAAwC,oBAAoB,oBAAoB,MAAM;AAEtF,WAAO;AAAA,EACR;AACA,SAAO;AACR;;"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { useConstantValueInvariant, useConstantLengthInvariant } from "@contember/react-utils";
|
|
2
2
|
import { useCallback } from "react";
|
|
3
3
|
import { useAccessorUpdateSubscription } from "./useAccessorUpdateSubscription.js";
|
|
4
|
+
import { useOnHasOneRelationPathConnectionUpdate } from "./useOnHasOneRelationPathConnectionUpdate.js";
|
|
4
5
|
import { useDesugaredRelativeSingleField } from "./useDesugaredRelativeSingleField.js";
|
|
5
6
|
import { useEntityKey } from "./useEntityKey.js";
|
|
6
7
|
import { useGetEntityByKey } from "./useGetEntityByKey.js";
|
|
7
|
-
import { useOnConnectionUpdate } from "../entityEvents/useOnConnectionUpdate.js";
|
|
8
8
|
function useField(sugaredRelativeSingleField) {
|
|
9
9
|
const relativeSingleField = useDesugaredRelativeSingleField(sugaredRelativeSingleField);
|
|
10
10
|
useConstantValueInvariant(
|
|
@@ -23,9 +23,7 @@ function useField(sugaredRelativeSingleField) {
|
|
|
23
23
|
"Cannot change the length of the hasOneRelation path!"
|
|
24
24
|
);
|
|
25
25
|
const [field, { update }] = useAccessorUpdateSubscription(getField);
|
|
26
|
-
|
|
27
|
-
useOnConnectionUpdate(relativeSingleField.hasOneRelationPath[0].field, update);
|
|
28
|
-
}
|
|
26
|
+
useOnHasOneRelationPathConnectionUpdate(relativeSingleField.hasOneRelationPath, update);
|
|
29
27
|
return field;
|
|
30
28
|
}
|
|
31
29
|
return void 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useField.js","sources":["../../../../../packages/react-binding/src/accessorPropagation/useField.ts"],"sourcesContent":["import { useConstantLengthInvariant, useConstantValueInvariant } from '@contember/react-utils'\nimport { useCallback } from 'react'\nimport { useEntityKey, useGetEntityByKey } from './index.js'\nimport type { FieldAccessor } from '@contember/binding'\nimport {
|
|
1
|
+
{"version":3,"file":"useField.js","sources":["../../../../../packages/react-binding/src/accessorPropagation/useField.ts"],"sourcesContent":["import { useConstantLengthInvariant, useConstantValueInvariant } from '@contember/react-utils'\nimport { useCallback } from 'react'\nimport { useEntityKey, useGetEntityByKey } from './index.js'\nimport type { FieldAccessor } from '@contember/binding'\nimport type { FieldValue, SugaredRelativeSingleField } from '@contember/binding'\nimport { useAccessorUpdateSubscription } from './useAccessorUpdateSubscription.js'\nimport { useOnHasOneRelationPathConnectionUpdate } from './useOnHasOneRelationPathConnectionUpdate.js'\nimport { useDesugaredRelativeSingleField } from './useDesugaredRelativeSingleField.js'\n\nfunction useField<Value extends FieldValue = FieldValue>(\n\tsugaredRelativeSingleField: string | SugaredRelativeSingleField,\n): FieldAccessor<Value>\nfunction useField<Value extends FieldValue = FieldValue>(\n\tsugaredRelativeSingleField: string | SugaredRelativeSingleField | undefined,\n): FieldAccessor<Value> | undefined\nfunction useField<Value extends FieldValue = FieldValue>(\n\tsugaredRelativeSingleField: string | SugaredRelativeSingleField | undefined,\n): FieldAccessor<Value> | undefined {\n\tconst relativeSingleField = useDesugaredRelativeSingleField(sugaredRelativeSingleField)\n\tuseConstantValueInvariant(\n\t\t!!relativeSingleField,\n\t\t'useField: cannot alternate between providing and omitting the argument.',\n\t)\n\n\tconst entityKey = useEntityKey()\n\tconst getEntityByKey = useGetEntityByKey()\n\tconst getField = useCallback(() => {\n\t\tconst parent = getEntityByKey(entityKey)\n\t\treturn parent.getField<Value>(relativeSingleField!)\n\t}, [entityKey, getEntityByKey, relativeSingleField])\n\n\tif (relativeSingleField) {\n\t\tuseConstantLengthInvariant(\n\t\t\trelativeSingleField.hasOneRelationPath,\n\t\t\t'Cannot change the length of the hasOneRelation path!',\n\t\t)\n\t\tconst [field, { update }] = useAccessorUpdateSubscription(getField)\n\n\t\tuseOnHasOneRelationPathConnectionUpdate(relativeSingleField.hasOneRelationPath, update)\n\n\t\treturn field\n\t}\n\treturn undefined\n}\n\nexport { useField }\n"],"names":[],"mappings":";;;;;;;AAeA,SAAS,SACR,4BACmC;AACnC,QAAM,sBAAsB,gCAAgC,0BAA0B;AACtF;AAAA,IACC,CAAC,CAAC;AAAA,IACF;AAAA,EAAA;AAGD,QAAM,YAAY,aAAA;AAClB,QAAM,iBAAiB,kBAAA;AACvB,QAAM,WAAW,YAAY,MAAM;AAClC,UAAM,SAAS,eAAe,SAAS;AACvC,WAAO,OAAO,SAAgB,mBAAoB;AAAA,EACnD,GAAG,CAAC,WAAW,gBAAgB,mBAAmB,CAAC;AAEnD,MAAI,qBAAqB;AACxB;AAAA,MACC,oBAAoB;AAAA,MACpB;AAAA,IAAA;AAED,UAAM,CAAC,OAAO,EAAE,QAAQ,IAAI,8BAA8B,QAAQ;AAElE,4CAAwC,oBAAoB,oBAAoB,MAAM;AAEtF,WAAO;AAAA,EACR;AACA,SAAO;AACR;"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const reactUtils = require("@contember/react-utils");
|
|
4
|
+
const React = require("react");
|
|
5
|
+
const useEntityKey = require("./useEntityKey.cjs");
|
|
6
|
+
const useGetEntityByKey = require("./useGetEntityByKey.cjs");
|
|
7
|
+
const useOnHasOneRelationPathConnectionUpdate = (hasOneRelationPath, update) => {
|
|
8
|
+
const entityKey = useEntityKey.useEntityKey();
|
|
9
|
+
const getEntityByKey = useGetEntityByKey.useGetEntityByKey();
|
|
10
|
+
const hopParentGetters = [];
|
|
11
|
+
if (hasOneRelationPath.length > 0) {
|
|
12
|
+
let hopParent = getEntityByKey(entityKey);
|
|
13
|
+
for (const [index, hop] of hasOneRelationPath.entries()) {
|
|
14
|
+
hopParentGetters.push(hopParent.getAccessor);
|
|
15
|
+
if (index < hasOneRelationPath.length - 1) {
|
|
16
|
+
hopParent = hopParent.getEntity({ hasOneRelationPath: [hop] });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const stableHopParentGetters = reactUtils.useObjectMemo(hopParentGetters);
|
|
21
|
+
React.useEffect(() => {
|
|
22
|
+
const unsubscribers = stableHopParentGetters.map(
|
|
23
|
+
(getHopParent, index) => getHopParent().addEventListener({ type: "connectionUpdate", key: hasOneRelationPath[index].field }, update)
|
|
24
|
+
);
|
|
25
|
+
return () => {
|
|
26
|
+
for (const unsubscribe of unsubscribers) {
|
|
27
|
+
unsubscribe();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}, [hasOneRelationPath, stableHopParentGetters, update]);
|
|
31
|
+
};
|
|
32
|
+
exports.useOnHasOneRelationPathConnectionUpdate = useOnHasOneRelationPathConnectionUpdate;
|
|
33
|
+
//# sourceMappingURL=useOnHasOneRelationPathConnectionUpdate.cjs.map
|
package/dist/development/src/accessorPropagation/useOnHasOneRelationPathConnectionUpdate.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOnHasOneRelationPathConnectionUpdate.cjs","sources":["../../../../../packages/react-binding/src/accessorPropagation/useOnHasOneRelationPathConnectionUpdate.ts"],"sourcesContent":["import type { EntityAccessor, HasOneRelation } from '@contember/binding'\nimport { useObjectMemo } from '@contember/react-utils'\nimport { useEffect } from 'react'\nimport { useEntityKey } from './useEntityKey.js'\nimport { useGetEntityByKey } from './useGetEntityByKey.js'\n\n/**\n * Calls `update` when any has-one relation along the path is reconnected, not only the first one.\n * Each hop is watched on the entity it currently hangs off, so the listeners move once an earlier hop is reconnected.\n */\nexport const useOnHasOneRelationPathConnectionUpdate = (hasOneRelationPath: HasOneRelation[], update: () => void): void => {\n\tconst entityKey = useEntityKey()\n\tconst getEntityByKey = useGetEntityByKey()\n\n\t// A getter is stable per entity realm, so this array changes exactly when a hop resolves to another entity.\n\tconst hopParentGetters: EntityAccessor.GetEntityAccessor[] = []\n\tif (hasOneRelationPath.length > 0) {\n\t\tlet hopParent = getEntityByKey(entityKey)\n\t\tfor (const [index, hop] of hasOneRelationPath.entries()) {\n\t\t\thopParentGetters.push(hopParent.getAccessor)\n\t\t\tif (index < hasOneRelationPath.length - 1) {\n\t\t\t\thopParent = hopParent.getEntity({ hasOneRelationPath: [hop] })\n\t\t\t}\n\t\t}\n\t}\n\tconst stableHopParentGetters = useObjectMemo(hopParentGetters)\n\n\tuseEffect(() => {\n\t\tconst unsubscribers = stableHopParentGetters.map((getHopParent, index) =>\n\t\t\tgetHopParent().addEventListener({ type: 'connectionUpdate', key: hasOneRelationPath[index].field }, update)\n\t\t)\n\t\treturn () => {\n\t\t\tfor (const unsubscribe of unsubscribers) {\n\t\t\t\tunsubscribe()\n\t\t\t}\n\t\t}\n\t}, [hasOneRelationPath, stableHopParentGetters, update])\n}\n"],"names":["useEntityKey","useGetEntityByKey","useObjectMemo","useEffect"],"mappings":";;;;;;AAUO,MAAM,0CAA0C,CAAC,oBAAsC,WAA6B;AAC1H,QAAM,YAAYA,aAAAA,aAAA;AAClB,QAAM,iBAAiBC,kBAAAA,kBAAA;AAGvB,QAAM,mBAAuD,CAAA;AAC7D,MAAI,mBAAmB,SAAS,GAAG;AAClC,QAAI,YAAY,eAAe,SAAS;AACxC,eAAW,CAAC,OAAO,GAAG,KAAK,mBAAmB,WAAW;AACxD,uBAAiB,KAAK,UAAU,WAAW;AAC3C,UAAI,QAAQ,mBAAmB,SAAS,GAAG;AAC1C,oBAAY,UAAU,UAAU,EAAE,oBAAoB,CAAC,GAAG,GAAG;AAAA,MAC9D;AAAA,IACD;AAAA,EACD;AACA,QAAM,yBAAyBC,WAAAA,cAAc,gBAAgB;AAE7DC,QAAAA,UAAU,MAAM;AACf,UAAM,gBAAgB,uBAAuB;AAAA,MAAI,CAAC,cAAc,UAC/D,aAAA,EAAe,iBAAiB,EAAE,MAAM,oBAAoB,KAAK,mBAAmB,KAAK,EAAE,MAAA,GAAS,MAAM;AAAA,IAAA;AAE3G,WAAO,MAAM;AACZ,iBAAW,eAAe,eAAe;AACxC,oBAAA;AAAA,MACD;AAAA,IACD;AAAA,EACD,GAAG,CAAC,oBAAoB,wBAAwB,MAAM,CAAC;AACxD;;"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useObjectMemo } from "@contember/react-utils";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
import { useEntityKey } from "./useEntityKey.js";
|
|
4
|
+
import { useGetEntityByKey } from "./useGetEntityByKey.js";
|
|
5
|
+
const useOnHasOneRelationPathConnectionUpdate = (hasOneRelationPath, update) => {
|
|
6
|
+
const entityKey = useEntityKey();
|
|
7
|
+
const getEntityByKey = useGetEntityByKey();
|
|
8
|
+
const hopParentGetters = [];
|
|
9
|
+
if (hasOneRelationPath.length > 0) {
|
|
10
|
+
let hopParent = getEntityByKey(entityKey);
|
|
11
|
+
for (const [index, hop] of hasOneRelationPath.entries()) {
|
|
12
|
+
hopParentGetters.push(hopParent.getAccessor);
|
|
13
|
+
if (index < hasOneRelationPath.length - 1) {
|
|
14
|
+
hopParent = hopParent.getEntity({ hasOneRelationPath: [hop] });
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const stableHopParentGetters = useObjectMemo(hopParentGetters);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
const unsubscribers = stableHopParentGetters.map(
|
|
21
|
+
(getHopParent, index) => getHopParent().addEventListener({ type: "connectionUpdate", key: hasOneRelationPath[index].field }, update)
|
|
22
|
+
);
|
|
23
|
+
return () => {
|
|
24
|
+
for (const unsubscribe of unsubscribers) {
|
|
25
|
+
unsubscribe();
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}, [hasOneRelationPath, stableHopParentGetters, update]);
|
|
29
|
+
};
|
|
30
|
+
export {
|
|
31
|
+
useOnHasOneRelationPathConnectionUpdate
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=useOnHasOneRelationPathConnectionUpdate.js.map
|
package/dist/development/src/accessorPropagation/useOnHasOneRelationPathConnectionUpdate.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOnHasOneRelationPathConnectionUpdate.js","sources":["../../../../../packages/react-binding/src/accessorPropagation/useOnHasOneRelationPathConnectionUpdate.ts"],"sourcesContent":["import type { EntityAccessor, HasOneRelation } from '@contember/binding'\nimport { useObjectMemo } from '@contember/react-utils'\nimport { useEffect } from 'react'\nimport { useEntityKey } from './useEntityKey.js'\nimport { useGetEntityByKey } from './useGetEntityByKey.js'\n\n/**\n * Calls `update` when any has-one relation along the path is reconnected, not only the first one.\n * Each hop is watched on the entity it currently hangs off, so the listeners move once an earlier hop is reconnected.\n */\nexport const useOnHasOneRelationPathConnectionUpdate = (hasOneRelationPath: HasOneRelation[], update: () => void): void => {\n\tconst entityKey = useEntityKey()\n\tconst getEntityByKey = useGetEntityByKey()\n\n\t// A getter is stable per entity realm, so this array changes exactly when a hop resolves to another entity.\n\tconst hopParentGetters: EntityAccessor.GetEntityAccessor[] = []\n\tif (hasOneRelationPath.length > 0) {\n\t\tlet hopParent = getEntityByKey(entityKey)\n\t\tfor (const [index, hop] of hasOneRelationPath.entries()) {\n\t\t\thopParentGetters.push(hopParent.getAccessor)\n\t\t\tif (index < hasOneRelationPath.length - 1) {\n\t\t\t\thopParent = hopParent.getEntity({ hasOneRelationPath: [hop] })\n\t\t\t}\n\t\t}\n\t}\n\tconst stableHopParentGetters = useObjectMemo(hopParentGetters)\n\n\tuseEffect(() => {\n\t\tconst unsubscribers = stableHopParentGetters.map((getHopParent, index) =>\n\t\t\tgetHopParent().addEventListener({ type: 'connectionUpdate', key: hasOneRelationPath[index].field }, update)\n\t\t)\n\t\treturn () => {\n\t\t\tfor (const unsubscribe of unsubscribers) {\n\t\t\t\tunsubscribe()\n\t\t\t}\n\t\t}\n\t}, [hasOneRelationPath, stableHopParentGetters, update])\n}\n"],"names":[],"mappings":";;;;AAUO,MAAM,0CAA0C,CAAC,oBAAsC,WAA6B;AAC1H,QAAM,YAAY,aAAA;AAClB,QAAM,iBAAiB,kBAAA;AAGvB,QAAM,mBAAuD,CAAA;AAC7D,MAAI,mBAAmB,SAAS,GAAG;AAClC,QAAI,YAAY,eAAe,SAAS;AACxC,eAAW,CAAC,OAAO,GAAG,KAAK,mBAAmB,WAAW;AACxD,uBAAiB,KAAK,UAAU,WAAW;AAC3C,UAAI,QAAQ,mBAAmB,SAAS,GAAG;AAC1C,oBAAY,UAAU,UAAU,EAAE,oBAAoB,CAAC,GAAG,GAAG;AAAA,MAC9D;AAAA,IACD;AAAA,EACD;AACA,QAAM,yBAAyB,cAAc,gBAAgB;AAE7D,YAAU,MAAM;AACf,UAAM,gBAAgB,uBAAuB;AAAA,MAAI,CAAC,cAAc,UAC/D,aAAA,EAAe,iBAAiB,EAAE,MAAM,oBAAoB,KAAK,mBAAmB,KAAK,EAAE,MAAA,GAAS,MAAM;AAAA,IAAA;AAE3G,WAAO,MAAM;AACZ,iBAAW,eAAe,eAAe;AACxC,oBAAA;AAAA,MACD;AAAA,IACD;AAAA,EACD,GAAG,CAAC,oBAAoB,wBAAwB,MAAM,CAAC;AACxD;"}
|
|
@@ -10,19 +10,21 @@ const useAccessorUpdateSubscription = (getAccessor) => {
|
|
|
10
10
|
setState(accessor);
|
|
11
11
|
getterRef.current = getAccessor;
|
|
12
12
|
}
|
|
13
|
+
const getSubscribedAccessor = accessor.getAccessor;
|
|
13
14
|
React.useEffect(() => {
|
|
14
15
|
let isStillSubscribed = true;
|
|
15
|
-
const unsubscribe =
|
|
16
|
+
const unsubscribe = getSubscribedAccessor().addEventListener({ type: "update" }, (newAccessor) => {
|
|
16
17
|
if (!isStillSubscribed || getterRef.current !== getAccessor) {
|
|
17
18
|
return;
|
|
18
19
|
}
|
|
19
20
|
setState(newAccessor);
|
|
20
21
|
});
|
|
22
|
+
setState(getAccessor());
|
|
21
23
|
return () => {
|
|
22
24
|
isStillSubscribed = false;
|
|
23
25
|
unsubscribe();
|
|
24
26
|
};
|
|
25
|
-
}, [getAccessor]);
|
|
27
|
+
}, [getAccessor, getSubscribedAccessor]);
|
|
26
28
|
const update = React.useCallback(() => {
|
|
27
29
|
setState(getAccessor());
|
|
28
30
|
}, [getAccessor]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAccessorUpdateSubscription.cjs","sources":["../../../../../packages/react-binding/src/accessorPropagation/useAccessorUpdateSubscription.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react'\n\n/**\n * It is VERY IMPORTANT for the parameter to be referentially stable!\n */\nexport const useAccessorUpdateSubscription = <\n\tAccessor extends {\n\t\taddEventListener: (event: { type: 'update' }, cb: (accessor: Accessor) => void) => () => void\n\t},\n>(getAccessor: () => Accessor): [Accessor, { update: () => void }] => {\n\tconst [state, setState] = useState<Accessor>(() => getAccessor())\n\tconst getterRef = useRef(getAccessor)\n\n\tlet accessor = state\n\tif (getterRef.current !== getAccessor) {\n\t\taccessor = getAccessor()\n\t\tsetState(accessor)\n\t\tgetterRef.current = getAccessor\n\t}\n\n\tuseEffect(() => {\n\t\tlet isStillSubscribed = true\n\t\tconst unsubscribe =
|
|
1
|
+
{"version":3,"file":"useAccessorUpdateSubscription.cjs","sources":["../../../../../packages/react-binding/src/accessorPropagation/useAccessorUpdateSubscription.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react'\n\n/**\n * It is VERY IMPORTANT for the parameter to be referentially stable!\n */\nexport const useAccessorUpdateSubscription = <\n\tAccessor extends {\n\t\taddEventListener: (event: { type: 'update' }, cb: (accessor: Accessor) => void) => () => void\n\t\tgetAccessor: () => Accessor\n\t},\n>(getAccessor: () => Accessor): [Accessor, { update: () => void }] => {\n\tconst [state, setState] = useState<Accessor>(() => getAccessor())\n\tconst getterRef = useRef(getAccessor)\n\n\tlet accessor = state\n\tif (getterRef.current !== getAccessor) {\n\t\taccessor = getAccessor()\n\t\tsetState(accessor)\n\t\tgetterRef.current = getAccessor\n\t}\n\n\t// A state node's getter is stable, so this changes exactly when `getAccessor` resolves to another node.\n\tconst getSubscribedAccessor = accessor.getAccessor\n\n\tuseEffect(() => {\n\t\tlet isStillSubscribed = true\n\t\tconst unsubscribe = getSubscribedAccessor().addEventListener({ type: 'update' }, newAccessor => {\n\t\t\tif (!isStillSubscribed || getterRef.current !== getAccessor) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tsetState(newAccessor)\n\t\t})\n\t\t// Catches up with updates that landed between the render and this subscription.\n\t\tsetState(getAccessor())\n\n\t\treturn () => {\n\t\t\tisStillSubscribed = false\n\t\t\tunsubscribe()\n\t\t}\n\t}, [getAccessor, getSubscribedAccessor])\n\n\tconst update = useCallback(() => {\n\t\tsetState(getAccessor())\n\t}, [getAccessor])\n\n\treturn [accessor, { update }]\n}\n"],"names":["useState","useRef","useEffect","useCallback"],"mappings":";;;AAKO,MAAM,gCAAgC,CAK3C,gBAAoE;AACrE,QAAM,CAAC,OAAO,QAAQ,IAAIA,MAAAA,SAAmB,MAAM,aAAa;AAChE,QAAM,YAAYC,MAAAA,OAAO,WAAW;AAEpC,MAAI,WAAW;AACf,MAAI,UAAU,YAAY,aAAa;AACtC,eAAW,YAAA;AACX,aAAS,QAAQ;AACjB,cAAU,UAAU;AAAA,EACrB;AAGA,QAAM,wBAAwB,SAAS;AAEvCC,QAAAA,UAAU,MAAM;AACf,QAAI,oBAAoB;AACxB,UAAM,cAAc,wBAAwB,iBAAiB,EAAE,MAAM,SAAA,GAAY,CAAA,gBAAe;AAC/F,UAAI,CAAC,qBAAqB,UAAU,YAAY,aAAa;AAC5D;AAAA,MACD;AACA,eAAS,WAAW;AAAA,IACrB,CAAC;AAED,aAAS,aAAa;AAEtB,WAAO,MAAM;AACZ,0BAAoB;AACpB,kBAAA;AAAA,IACD;AAAA,EACD,GAAG,CAAC,aAAa,qBAAqB,CAAC;AAEvC,QAAM,SAASC,MAAAA,YAAY,MAAM;AAChC,aAAS,aAAa;AAAA,EACvB,GAAG,CAAC,WAAW,CAAC;AAEhB,SAAO,CAAC,UAAU,EAAE,QAAQ;AAC7B;;"}
|
|
@@ -8,19 +8,21 @@ const useAccessorUpdateSubscription = (getAccessor) => {
|
|
|
8
8
|
setState(accessor);
|
|
9
9
|
getterRef.current = getAccessor;
|
|
10
10
|
}
|
|
11
|
+
const getSubscribedAccessor = accessor.getAccessor;
|
|
11
12
|
useEffect(() => {
|
|
12
13
|
let isStillSubscribed = true;
|
|
13
|
-
const unsubscribe =
|
|
14
|
+
const unsubscribe = getSubscribedAccessor().addEventListener({ type: "update" }, (newAccessor) => {
|
|
14
15
|
if (!isStillSubscribed || getterRef.current !== getAccessor) {
|
|
15
16
|
return;
|
|
16
17
|
}
|
|
17
18
|
setState(newAccessor);
|
|
18
19
|
});
|
|
20
|
+
setState(getAccessor());
|
|
19
21
|
return () => {
|
|
20
22
|
isStillSubscribed = false;
|
|
21
23
|
unsubscribe();
|
|
22
24
|
};
|
|
23
|
-
}, [getAccessor]);
|
|
25
|
+
}, [getAccessor, getSubscribedAccessor]);
|
|
24
26
|
const update = useCallback(() => {
|
|
25
27
|
setState(getAccessor());
|
|
26
28
|
}, [getAccessor]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAccessorUpdateSubscription.js","sources":["../../../../../packages/react-binding/src/accessorPropagation/useAccessorUpdateSubscription.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react'\n\n/**\n * It is VERY IMPORTANT for the parameter to be referentially stable!\n */\nexport const useAccessorUpdateSubscription = <\n\tAccessor extends {\n\t\taddEventListener: (event: { type: 'update' }, cb: (accessor: Accessor) => void) => () => void\n\t},\n>(getAccessor: () => Accessor): [Accessor, { update: () => void }] => {\n\tconst [state, setState] = useState<Accessor>(() => getAccessor())\n\tconst getterRef = useRef(getAccessor)\n\n\tlet accessor = state\n\tif (getterRef.current !== getAccessor) {\n\t\taccessor = getAccessor()\n\t\tsetState(accessor)\n\t\tgetterRef.current = getAccessor\n\t}\n\n\tuseEffect(() => {\n\t\tlet isStillSubscribed = true\n\t\tconst unsubscribe =
|
|
1
|
+
{"version":3,"file":"useAccessorUpdateSubscription.js","sources":["../../../../../packages/react-binding/src/accessorPropagation/useAccessorUpdateSubscription.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react'\n\n/**\n * It is VERY IMPORTANT for the parameter to be referentially stable!\n */\nexport const useAccessorUpdateSubscription = <\n\tAccessor extends {\n\t\taddEventListener: (event: { type: 'update' }, cb: (accessor: Accessor) => void) => () => void\n\t\tgetAccessor: () => Accessor\n\t},\n>(getAccessor: () => Accessor): [Accessor, { update: () => void }] => {\n\tconst [state, setState] = useState<Accessor>(() => getAccessor())\n\tconst getterRef = useRef(getAccessor)\n\n\tlet accessor = state\n\tif (getterRef.current !== getAccessor) {\n\t\taccessor = getAccessor()\n\t\tsetState(accessor)\n\t\tgetterRef.current = getAccessor\n\t}\n\n\t// A state node's getter is stable, so this changes exactly when `getAccessor` resolves to another node.\n\tconst getSubscribedAccessor = accessor.getAccessor\n\n\tuseEffect(() => {\n\t\tlet isStillSubscribed = true\n\t\tconst unsubscribe = getSubscribedAccessor().addEventListener({ type: 'update' }, newAccessor => {\n\t\t\tif (!isStillSubscribed || getterRef.current !== getAccessor) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tsetState(newAccessor)\n\t\t})\n\t\t// Catches up with updates that landed between the render and this subscription.\n\t\tsetState(getAccessor())\n\n\t\treturn () => {\n\t\t\tisStillSubscribed = false\n\t\t\tunsubscribe()\n\t\t}\n\t}, [getAccessor, getSubscribedAccessor])\n\n\tconst update = useCallback(() => {\n\t\tsetState(getAccessor())\n\t}, [getAccessor])\n\n\treturn [accessor, { update }]\n}\n"],"names":[],"mappings":";AAKO,MAAM,gCAAgC,CAK3C,gBAAoE;AACrE,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAmB,MAAM,aAAa;AAChE,QAAM,YAAY,OAAO,WAAW;AAEpC,MAAI,WAAW;AACf,MAAI,UAAU,YAAY,aAAa;AACtC,eAAW,YAAA;AACX,aAAS,QAAQ;AACjB,cAAU,UAAU;AAAA,EACrB;AAGA,QAAM,wBAAwB,SAAS;AAEvC,YAAU,MAAM;AACf,QAAI,oBAAoB;AACxB,UAAM,cAAc,wBAAwB,iBAAiB,EAAE,MAAM,SAAA,GAAY,CAAA,gBAAe;AAC/F,UAAI,CAAC,qBAAqB,UAAU,YAAY,aAAa;AAC5D;AAAA,MACD;AACA,eAAS,WAAW;AAAA,IACrB,CAAC;AAED,aAAS,aAAa;AAEtB,WAAO,MAAM;AACZ,0BAAoB;AACpB,kBAAA;AAAA,IACD;AAAA,EACD,GAAG,CAAC,aAAa,qBAAqB,CAAC;AAEvC,QAAM,SAAS,YAAY,MAAM;AAChC,aAAS,aAAa;AAAA,EACvB,GAAG,CAAC,WAAW,CAAC;AAEhB,SAAO,CAAC,UAAU,EAAE,QAAQ;AAC7B;"}
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const reactUtils = require("@contember/react-utils");
|
|
4
4
|
const React = require("react");
|
|
5
5
|
const useAccessorUpdateSubscription = require("./useAccessorUpdateSubscription.cjs");
|
|
6
|
+
const useOnHasOneRelationPathConnectionUpdate = require("./useOnHasOneRelationPathConnectionUpdate.cjs");
|
|
6
7
|
const useDesugaredRelativeSingleEntity = require("./useDesugaredRelativeSingleEntity.cjs");
|
|
7
|
-
const useOnConnectionUpdate = require("../entityEvents/useOnConnectionUpdate.cjs");
|
|
8
8
|
const useEntityKey = require("./useEntityKey.cjs");
|
|
9
9
|
const useGetEntityByKey = require("./useGetEntityByKey.cjs");
|
|
10
10
|
function useEntity(...entity) {
|
|
@@ -27,9 +27,7 @@ function useEntity(...entity) {
|
|
|
27
27
|
"Cannot change the length of the hasOneRelation path!"
|
|
28
28
|
);
|
|
29
29
|
const [entity2, { update }] = useAccessorUpdateSubscription.useAccessorUpdateSubscription(getEntity);
|
|
30
|
-
|
|
31
|
-
useOnConnectionUpdate.useOnConnectionUpdate(relativeSingleEntity.hasOneRelationPath[0].field, update);
|
|
32
|
-
}
|
|
30
|
+
useOnHasOneRelationPathConnectionUpdate.useOnHasOneRelationPathConnectionUpdate(relativeSingleEntity.hasOneRelationPath, update);
|
|
33
31
|
return entity2;
|
|
34
32
|
}
|
|
35
33
|
return void 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEntity.cjs","sources":["../../../../../packages/react-binding/src/accessorPropagation/useEntity.ts"],"sourcesContent":["import { useConstantLengthInvariant, useConstantValueInvariant } from '@contember/react-utils'\nimport { useCallback } from 'react'\nimport { useEntityKey, useGetEntityByKey } from './index.js'\nimport type { EntityAccessor } from '@contember/binding'\nimport {
|
|
1
|
+
{"version":3,"file":"useEntity.cjs","sources":["../../../../../packages/react-binding/src/accessorPropagation/useEntity.ts"],"sourcesContent":["import { useConstantLengthInvariant, useConstantValueInvariant } from '@contember/react-utils'\nimport { useCallback } from 'react'\nimport { useEntityKey, useGetEntityByKey } from './index.js'\nimport type { EntityAccessor } from '@contember/binding'\nimport type { SugaredRelativeSingleEntity } from '@contember/binding'\nimport { useAccessorUpdateSubscription } from './useAccessorUpdateSubscription.js'\nimport { useOnHasOneRelationPathConnectionUpdate } from './useOnHasOneRelationPathConnectionUpdate.js'\nimport { useDesugaredRelativeSingleEntity } from './useDesugaredRelativeSingleEntity.js'\n\nfunction useEntity(): EntityAccessor\nfunction useEntity(sugaredRelativeSingleEntity: string | SugaredRelativeSingleEntity): EntityAccessor\nfunction useEntity(\n\tsugaredRelativeSingleEntity: string | SugaredRelativeSingleEntity | undefined,\n): EntityAccessor | undefined\nfunction useEntity(...entity: [] | [string | SugaredRelativeSingleEntity | undefined]): EntityAccessor | undefined {\n\tuseConstantValueInvariant(entity.length, 'useEntity: cannot alternate between providing and omitting the argument.')\n\n\tconst entityKey = useEntityKey()\n\tconst getEntityByKey = useGetEntityByKey()\n\n\tif (entity.length === 0) {\n\t\tconst getEntityAccessor = useCallback(() => getEntityByKey(entityKey), [entityKey, getEntityByKey])\n\t\treturn useAccessorUpdateSubscription(getEntityAccessor)[0]\n\t}\n\tconst sugaredRelativeSingleEntity = entity[0]\n\n\tconst relativeSingleEntity = useDesugaredRelativeSingleEntity(sugaredRelativeSingleEntity)\n\tconst getEntity = useCallback(() => {\n\t\tconst parent = getEntityByKey(entityKey)\n\t\treturn parent.getEntity(relativeSingleEntity!)\n\t}, [entityKey, getEntityByKey, relativeSingleEntity])\n\n\tif (relativeSingleEntity) {\n\t\tuseConstantLengthInvariant(\n\t\t\trelativeSingleEntity.hasOneRelationPath,\n\t\t\t'Cannot change the length of the hasOneRelation path!',\n\t\t)\n\t\tconst [entity, { update }] = useAccessorUpdateSubscription(getEntity)\n\n\t\tuseOnHasOneRelationPathConnectionUpdate(relativeSingleEntity.hasOneRelationPath, update)\n\n\t\treturn entity\n\t}\n\treturn undefined\n}\n\nexport { useEntity }\n"],"names":["useConstantValueInvariant","useEntityKey","useGetEntityByKey","useCallback","useAccessorUpdateSubscription","useDesugaredRelativeSingleEntity","useConstantLengthInvariant","entity","useOnHasOneRelationPathConnectionUpdate"],"mappings":";;;;;;;;;AAcA,SAAS,aAAa,QAA6F;AAClHA,uCAA0B,OAAO,QAAQ,0EAA0E;AAEnH,QAAM,YAAYC,aAAAA,aAAA;AAClB,QAAM,iBAAiBC,kBAAAA,kBAAA;AAEvB,MAAI,OAAO,WAAW,GAAG;AACxB,UAAM,oBAAoBC,MAAAA,YAAY,MAAM,eAAe,SAAS,GAAG,CAAC,WAAW,cAAc,CAAC;AAClG,WAAOC,8BAAAA,8BAA8B,iBAAiB,EAAE,CAAC;AAAA,EAC1D;AACA,QAAM,8BAA8B,OAAO,CAAC;AAE5C,QAAM,uBAAuBC,iCAAAA,iCAAiC,2BAA2B;AACzF,QAAM,YAAYF,MAAAA,YAAY,MAAM;AACnC,UAAM,SAAS,eAAe,SAAS;AACvC,WAAO,OAAO,UAAU,oBAAqB;AAAA,EAC9C,GAAG,CAAC,WAAW,gBAAgB,oBAAoB,CAAC;AAEpD,MAAI,sBAAsB;AACzBG,eAAAA;AAAAA,MACC,qBAAqB;AAAA,MACrB;AAAA,IAAA;AAED,UAAM,CAACC,SAAQ,EAAE,QAAQ,IAAIH,8BAAAA,8BAA8B,SAAS;AAEpEI,oFAAwC,qBAAqB,oBAAoB,MAAM;AAEvF,WAAOD;AAAAA,EACR;AACA,SAAO;AACR;;"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useConstantValueInvariant, useConstantLengthInvariant } from "@contember/react-utils";
|
|
2
2
|
import { useCallback } from "react";
|
|
3
3
|
import { useAccessorUpdateSubscription } from "./useAccessorUpdateSubscription.js";
|
|
4
|
+
import { useOnHasOneRelationPathConnectionUpdate } from "./useOnHasOneRelationPathConnectionUpdate.js";
|
|
4
5
|
import { useDesugaredRelativeSingleEntity } from "./useDesugaredRelativeSingleEntity.js";
|
|
5
|
-
import { useOnConnectionUpdate } from "../entityEvents/useOnConnectionUpdate.js";
|
|
6
6
|
import { useEntityKey } from "./useEntityKey.js";
|
|
7
7
|
import { useGetEntityByKey } from "./useGetEntityByKey.js";
|
|
8
8
|
function useEntity(...entity) {
|
|
@@ -25,9 +25,7 @@ function useEntity(...entity) {
|
|
|
25
25
|
"Cannot change the length of the hasOneRelation path!"
|
|
26
26
|
);
|
|
27
27
|
const [entity2, { update }] = useAccessorUpdateSubscription(getEntity);
|
|
28
|
-
|
|
29
|
-
useOnConnectionUpdate(relativeSingleEntity.hasOneRelationPath[0].field, update);
|
|
30
|
-
}
|
|
28
|
+
useOnHasOneRelationPathConnectionUpdate(relativeSingleEntity.hasOneRelationPath, update);
|
|
31
29
|
return entity2;
|
|
32
30
|
}
|
|
33
31
|
return void 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEntity.js","sources":["../../../../../packages/react-binding/src/accessorPropagation/useEntity.ts"],"sourcesContent":["import { useConstantLengthInvariant, useConstantValueInvariant } from '@contember/react-utils'\nimport { useCallback } from 'react'\nimport { useEntityKey, useGetEntityByKey } from './index.js'\nimport type { EntityAccessor } from '@contember/binding'\nimport {
|
|
1
|
+
{"version":3,"file":"useEntity.js","sources":["../../../../../packages/react-binding/src/accessorPropagation/useEntity.ts"],"sourcesContent":["import { useConstantLengthInvariant, useConstantValueInvariant } from '@contember/react-utils'\nimport { useCallback } from 'react'\nimport { useEntityKey, useGetEntityByKey } from './index.js'\nimport type { EntityAccessor } from '@contember/binding'\nimport type { SugaredRelativeSingleEntity } from '@contember/binding'\nimport { useAccessorUpdateSubscription } from './useAccessorUpdateSubscription.js'\nimport { useOnHasOneRelationPathConnectionUpdate } from './useOnHasOneRelationPathConnectionUpdate.js'\nimport { useDesugaredRelativeSingleEntity } from './useDesugaredRelativeSingleEntity.js'\n\nfunction useEntity(): EntityAccessor\nfunction useEntity(sugaredRelativeSingleEntity: string | SugaredRelativeSingleEntity): EntityAccessor\nfunction useEntity(\n\tsugaredRelativeSingleEntity: string | SugaredRelativeSingleEntity | undefined,\n): EntityAccessor | undefined\nfunction useEntity(...entity: [] | [string | SugaredRelativeSingleEntity | undefined]): EntityAccessor | undefined {\n\tuseConstantValueInvariant(entity.length, 'useEntity: cannot alternate between providing and omitting the argument.')\n\n\tconst entityKey = useEntityKey()\n\tconst getEntityByKey = useGetEntityByKey()\n\n\tif (entity.length === 0) {\n\t\tconst getEntityAccessor = useCallback(() => getEntityByKey(entityKey), [entityKey, getEntityByKey])\n\t\treturn useAccessorUpdateSubscription(getEntityAccessor)[0]\n\t}\n\tconst sugaredRelativeSingleEntity = entity[0]\n\n\tconst relativeSingleEntity = useDesugaredRelativeSingleEntity(sugaredRelativeSingleEntity)\n\tconst getEntity = useCallback(() => {\n\t\tconst parent = getEntityByKey(entityKey)\n\t\treturn parent.getEntity(relativeSingleEntity!)\n\t}, [entityKey, getEntityByKey, relativeSingleEntity])\n\n\tif (relativeSingleEntity) {\n\t\tuseConstantLengthInvariant(\n\t\t\trelativeSingleEntity.hasOneRelationPath,\n\t\t\t'Cannot change the length of the hasOneRelation path!',\n\t\t)\n\t\tconst [entity, { update }] = useAccessorUpdateSubscription(getEntity)\n\n\t\tuseOnHasOneRelationPathConnectionUpdate(relativeSingleEntity.hasOneRelationPath, update)\n\n\t\treturn entity\n\t}\n\treturn undefined\n}\n\nexport { useEntity }\n"],"names":["entity"],"mappings":";;;;;;;AAcA,SAAS,aAAa,QAA6F;AAClH,4BAA0B,OAAO,QAAQ,0EAA0E;AAEnH,QAAM,YAAY,aAAA;AAClB,QAAM,iBAAiB,kBAAA;AAEvB,MAAI,OAAO,WAAW,GAAG;AACxB,UAAM,oBAAoB,YAAY,MAAM,eAAe,SAAS,GAAG,CAAC,WAAW,cAAc,CAAC;AAClG,WAAO,8BAA8B,iBAAiB,EAAE,CAAC;AAAA,EAC1D;AACA,QAAM,8BAA8B,OAAO,CAAC;AAE5C,QAAM,uBAAuB,iCAAiC,2BAA2B;AACzF,QAAM,YAAY,YAAY,MAAM;AACnC,UAAM,SAAS,eAAe,SAAS;AACvC,WAAO,OAAO,UAAU,oBAAqB;AAAA,EAC9C,GAAG,CAAC,WAAW,gBAAgB,oBAAoB,CAAC;AAEpD,MAAI,sBAAsB;AACzB;AAAA,MACC,qBAAqB;AAAA,MACrB;AAAA,IAAA;AAED,UAAM,CAACA,SAAQ,EAAE,QAAQ,IAAI,8BAA8B,SAAS;AAEpE,4CAAwC,qBAAqB,oBAAoB,MAAM;AAEvF,WAAOA;AAAAA,EACR;AACA,SAAO;AACR;"}
|
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const reactUtils = require("@contember/react-utils");
|
|
4
4
|
const React = require("react");
|
|
5
5
|
const useAccessorUpdateSubscription = require("./useAccessorUpdateSubscription.cjs");
|
|
6
|
+
const useOnHasOneRelationPathConnectionUpdate = require("./useOnHasOneRelationPathConnectionUpdate.cjs");
|
|
6
7
|
const useDesugaredRelativeEntityList = require("./useDesugaredRelativeEntityList.cjs");
|
|
7
8
|
const useEntityKey = require("./useEntityKey.cjs");
|
|
8
9
|
const useGetEntityByKey = require("./useGetEntityByKey.cjs");
|
|
9
|
-
const useOnConnectionUpdate = require("../entityEvents/useOnConnectionUpdate.cjs");
|
|
10
10
|
function useEntityList(sugaredRelativeEntityList) {
|
|
11
11
|
const relativeEntityList = useDesugaredRelativeEntityList.useDesugaredRelativeEntityList(sugaredRelativeEntityList);
|
|
12
12
|
reactUtils.useConstantValueInvariant(
|
|
@@ -25,9 +25,7 @@ function useEntityList(sugaredRelativeEntityList) {
|
|
|
25
25
|
"Cannot change the length of the hasOneRelation path!"
|
|
26
26
|
);
|
|
27
27
|
const [entityList, { update }] = useAccessorUpdateSubscription.useAccessorUpdateSubscription(getEntityList);
|
|
28
|
-
|
|
29
|
-
useOnConnectionUpdate.useOnConnectionUpdate(relativeEntityList.hasOneRelationPath[0].field, update);
|
|
30
|
-
}
|
|
28
|
+
useOnHasOneRelationPathConnectionUpdate.useOnHasOneRelationPathConnectionUpdate(relativeEntityList.hasOneRelationPath, update);
|
|
31
29
|
return entityList;
|
|
32
30
|
}
|
|
33
31
|
return void 0;
|