@tamagui/use-event 2.0.0-rc.8 → 2.0.0
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/cjs/index.cjs +7 -5
- package/dist/cjs/index.native.js +7 -5
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/useEvent.cjs +13 -11
- package/dist/cjs/useEvent.native.js +13 -11
- package/dist/cjs/useEvent.native.js.map +1 -1
- package/dist/cjs/useGet.cjs +29 -26
- package/dist/cjs/useGet.native.js +33 -28
- package/dist/cjs/useGet.native.js.map +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -6
- package/dist/esm/useEvent.mjs +1 -1
- package/dist/esm/useEvent.mjs.map +1 -1
- package/dist/esm/useEvent.native.js +1 -1
- package/dist/esm/useEvent.native.js.map +1 -1
- package/dist/esm/useGet.mjs +4 -3
- package/dist/esm/useGet.mjs.map +1 -1
- package/dist/esm/useGet.native.js +8 -5
- package/dist/esm/useGet.native.js.map +1 -1
- package/package.json +6 -11
- package/src/useGet.ts +8 -2
- package/types/index.d.ts.map +2 -2
- package/types/useEvent.d.ts.map +2 -2
- package/types/useGet.d.ts.map +4 -4
- package/dist/cjs/index.js +0 -16
- package/dist/cjs/index.js.map +0 -6
- package/dist/cjs/useEvent.js +0 -27
- package/dist/cjs/useEvent.js.map +0 -6
- package/dist/cjs/useGet.js +0 -38
- package/dist/cjs/useGet.js.map +0 -6
- package/dist/esm/useEvent.js +0 -11
- package/dist/esm/useEvent.js.map +0 -6
- package/dist/esm/useGet.js +0 -15
- package/dist/esm/useGet.js.map +0 -6
package/dist/cjs/index.cjs
CHANGED
|
@@ -3,15 +3,17 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
7
8
|
get: () => from[key],
|
|
8
9
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
9
10
|
});
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
13
15
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
14
|
-
value:
|
|
16
|
+
value: true
|
|
15
17
|
}), mod);
|
|
16
18
|
var index_exports = {};
|
|
17
19
|
module.exports = __toCommonJS(index_exports);
|
package/dist/cjs/index.native.js
CHANGED
|
@@ -5,15 +5,17 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __copyProps = (to, from, except, desc) => {
|
|
8
|
-
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
9
10
|
get: () => from[key],
|
|
10
11
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
11
12
|
});
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
17
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
16
|
-
value:
|
|
18
|
+
value: true
|
|
17
19
|
}), mod);
|
|
18
20
|
var index_exports = {};
|
|
19
21
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","module","exports","__reExport","require"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","module","exports","__reExport","require"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAP,YAAc,CAAAK,aAAA;AACdG,UAAA,CAAAH,aAAA,EAAcI,OAAA,wBADd,EAAAH,MAAA,CAAAC,OAAA","ignoreList":[]}
|
package/dist/cjs/useEvent.cjs
CHANGED
|
@@ -3,20 +3,22 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __export = (target, all) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
14
|
get: () => from[key],
|
|
14
15
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
16
|
});
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
18
20
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
-
value:
|
|
21
|
+
value: true
|
|
20
22
|
}), mod);
|
|
21
23
|
var useEvent_exports = {};
|
|
22
24
|
__export(useEvent_exports, {
|
|
@@ -25,7 +27,7 @@ __export(useEvent_exports, {
|
|
|
25
27
|
module.exports = __toCommonJS(useEvent_exports);
|
|
26
28
|
var import_useGet = require("./useGet.cjs");
|
|
27
29
|
function useEvent(callback) {
|
|
28
|
-
return (0, import_useGet.useGet)(callback, defaultValue,
|
|
30
|
+
return (0, import_useGet.useGet)(callback, defaultValue, true);
|
|
29
31
|
}
|
|
30
32
|
const defaultValue = () => {
|
|
31
33
|
throw new Error("Cannot call an event handler while rendering.");
|
|
@@ -5,20 +5,22 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
16
|
get: () => from[key],
|
|
16
17
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
-
value:
|
|
23
|
+
value: true
|
|
22
24
|
}), mod);
|
|
23
25
|
var useEvent_exports = {};
|
|
24
26
|
__export(useEvent_exports, {
|
|
@@ -27,7 +29,7 @@ __export(useEvent_exports, {
|
|
|
27
29
|
module.exports = __toCommonJS(useEvent_exports);
|
|
28
30
|
var import_useGet = require("./useGet.native.js");
|
|
29
31
|
function useEvent(callback) {
|
|
30
|
-
return (0, import_useGet.useGet)(callback, defaultValue,
|
|
32
|
+
return (0, import_useGet.useGet)(callback, defaultValue, true);
|
|
31
33
|
}
|
|
32
34
|
var defaultValue = function () {
|
|
33
35
|
throw new Error("Cannot call an event handler while rendering.");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useEvent_exports","__export","useEvent","module","exports","import_useGet","require","callback","useGet","defaultValue","Error"],"sources":["../../src/useEvent.ts"],"sourcesContent":[null],"mappings":"
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useEvent_exports","__export","useEvent","module","exports","import_useGet","require","callback","useGet","defaultValue","Error"],"sources":["../../src/useEvent.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,gBAAA;AAAAC,QAAA,CAAAD,gBAAA;EAAAE,QAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAT,YAAuB,CAAAK,gBAAA;AAIhB,IAAAK,aAAS,GAAgCC,OAAA,CAAiB;AAC/D,SAAAJ,QAAOA,CAAAK,QAAA;EACT,WAAAF,aAAA,CAAAG,MAAA,EAAAD,QAAA,EAAAE,YAAA;AAEA;AACE,IAAAA,YAAU,GAAM,SAAAA,CAAA;EAClB,UAAAC,KAAA","ignoreList":[]}
|
package/dist/cjs/useGet.cjs
CHANGED
|
@@ -2,43 +2,46 @@ var __create = Object.create;
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
6
|
-
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
16
|
get: () => from[key],
|
|
16
17
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: true
|
|
30
|
+
}) : target, mod));
|
|
31
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: true
|
|
33
|
+
}), mod);
|
|
32
34
|
var useGet_exports = {};
|
|
33
35
|
__export(useGet_exports, {
|
|
34
36
|
useGet: () => useGet
|
|
35
37
|
});
|
|
36
38
|
module.exports = __toCommonJS(useGet_exports);
|
|
37
|
-
var
|
|
38
|
-
|
|
39
|
+
var React = __toESM(require("react"), 1);
|
|
40
|
+
const useIsomorphicInsertionEffect = React.useInsertionEffect || React.useLayoutEffect;
|
|
39
41
|
function useGet(currentValue, initialValue, forwardToFunction) {
|
|
40
42
|
const curRef = React.useRef(initialValue ?? currentValue);
|
|
41
|
-
|
|
43
|
+
useIsomorphicInsertionEffect(() => {
|
|
42
44
|
curRef.current = currentValue;
|
|
43
|
-
})
|
|
45
|
+
});
|
|
46
|
+
return React.useCallback(forwardToFunction ? (...args) => curRef.current?.apply(null, args) : () => curRef.current, []);
|
|
44
47
|
}
|
|
@@ -4,46 +4,51 @@ var __create = Object.create;
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
8
|
-
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
9
|
var __export = (target, all) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: true
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
18
|
get: () => from[key],
|
|
18
19
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
20
|
});
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
22
24
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
30
|
+
value: mod,
|
|
31
|
+
enumerable: true
|
|
32
|
+
}) : target, mod));
|
|
33
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
34
|
+
value: true
|
|
35
|
+
}), mod);
|
|
34
36
|
var useGet_exports = {};
|
|
35
37
|
__export(useGet_exports, {
|
|
36
38
|
useGet: () => useGet
|
|
37
39
|
});
|
|
38
40
|
module.exports = __toCommonJS(useGet_exports);
|
|
39
|
-
var
|
|
40
|
-
|
|
41
|
+
var React = __toESM(require("react"), 1);
|
|
42
|
+
var useIsomorphicInsertionEffect = React.useInsertionEffect || React.useLayoutEffect;
|
|
41
43
|
function useGet(currentValue, initialValue, forwardToFunction) {
|
|
42
|
-
var curRef = React.useRef(initialValue
|
|
43
|
-
|
|
44
|
+
var curRef = React.useRef(initialValue !== null && initialValue !== void 0 ? initialValue : currentValue);
|
|
45
|
+
useIsomorphicInsertionEffect(function () {
|
|
44
46
|
curRef.current = currentValue;
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
+
});
|
|
48
|
+
return React.useCallback(forwardToFunction ? function () {
|
|
49
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
50
|
+
args[_key] = arguments[_key];
|
|
51
|
+
}
|
|
47
52
|
var _curRef_current;
|
|
48
53
|
return (_curRef_current = curRef.current) === null || _curRef_current === void 0 ? void 0 : _curRef_current.apply(null, args);
|
|
49
54
|
} : function () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useGet_exports","__export","useGet","module","exports","
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useGet_exports","__export","useGet","module","exports","React","__toESM","require","useIsomorphicInsertionEffect","useInsertionEffect","useLayoutEffect","currentValue","initialValue","forwardToFunction","curRef","useRef","current","useCallback","_len","arguments","length","args","Array","_key"],"sources":["../../src/useGet.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,cAAA;AAAAC,QAAA,CAAAD,cAAA;EAAAE,MAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAuB,GAAAT,YAAA,CAAAK,cAAA;AAOvB,IAAAK,KAAM,GAAAC,OAAA,CAAAC,OAAA,WAA+B;AAI9B,IAAAC,4BAEL,GAAAH,KAAA,CAAAI,kBACA,IACSJ,KAAA,CAAAK,eAAA;AACT,SAAMR,OAAAS,YAAe,EAAYC,YAAA,EAAAC,iBAA4B;EAC7D,IAAAC,MAAA,GAAAT,KAAA,CAAAU,MAAA,CAAAH,YAAmC,aAAAA,YAAA,cAAAA,YAAA,GAAAD,YAAA;EACjCH,4BAAiB;IAClBM,MAAA,CAAAE,OAAA,GAAAL,YAAA;EAED;EAAa,OACXN,KAAA,CAAAY,WACI,CAAAJ,iBAAoB,eAAS;IAEjC,KAAC,IAAAK,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAAAC,IAAA,OAAAC,KAAA,CAAAJ,IAAA,GAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;MACHF,IAAA,CAAAE,IAAA,IAAAJ,SAAA,CAAAI,IAAA;IACF","ignoreList":[]}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./useEvent";
|
|
2
|
-
export * from "./useGet";
|
|
1
|
+
export * from "./useEvent.mjs";
|
|
2
|
+
export * from "./useGet.mjs";
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
package/dist/esm/useEvent.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useGet","useEvent","callback","defaultValue","Error"],"sources":["../../src/useEvent.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,MAAA,QAAc;AAIhB,SAASC,SAAgCC,QAAA,EAAiB;EAC/D,OAAOF,MAAA,CAAOE,QAAA,EAAUC,YAAA,EAAc,
|
|
1
|
+
{"version":3,"names":["useGet","useEvent","callback","defaultValue","Error"],"sources":["../../src/useEvent.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,MAAA,QAAc;AAIhB,SAASC,SAAgCC,QAAA,EAAiB;EAC/D,OAAOF,MAAA,CAAOE,QAAA,EAAUC,YAAA,EAAc,IAAI;AAC5C;AAEA,MAAMA,YAAA,GAAeA,CAAA,KAAM;EACzB,MAAM,IAAIC,KAAA,CAAM,+CAA+C;AACjE","ignoreList":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useGet } from "./useGet.native.js";
|
|
2
2
|
function useEvent(callback) {
|
|
3
|
-
return useGet(callback, defaultValue,
|
|
3
|
+
return useGet(callback, defaultValue, true);
|
|
4
4
|
}
|
|
5
5
|
var defaultValue = function () {
|
|
6
6
|
throw new Error("Cannot call an event handler while rendering.");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useGet","useEvent","callback","defaultValue","Error"],"sources":["../../src/useEvent.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,MAAA,QAAc;AAIhB,SAASC,SAAgCC,QAAA,EAAiB;EAC/D,OAAOF,MAAA,CAAOE,QAAA,EAAUC,YAAA,EAAc,
|
|
1
|
+
{"version":3,"names":["useGet","useEvent","callback","defaultValue","Error"],"sources":["../../src/useEvent.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,MAAA,QAAc;AAIhB,SAASC,SAAgCC,QAAA,EAAiB;EAC/D,OAAOF,MAAA,CAAOE,QAAA,EAAUC,YAAA,EAAc,IAAI;AAC5C;AAEA,IAAAA,YAAM,YAAAA,CAAA,EAAqB;EACzB,MAAM,IAAIC,KAAA,CAAM,+CAA+C;AACjE","ignoreList":[]}
|
package/dist/esm/useGet.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { useIsomorphicLayoutEffect } from "@tamagui/constants";
|
|
2
1
|
import * as React from "react";
|
|
2
|
+
const useIsomorphicInsertionEffect = React.useInsertionEffect || React.useLayoutEffect;
|
|
3
3
|
function useGet(currentValue, initialValue, forwardToFunction) {
|
|
4
4
|
const curRef = React.useRef(initialValue ?? currentValue);
|
|
5
|
-
|
|
5
|
+
useIsomorphicInsertionEffect(() => {
|
|
6
6
|
curRef.current = currentValue;
|
|
7
|
-
})
|
|
7
|
+
});
|
|
8
|
+
return React.useCallback(forwardToFunction ? (...args) => curRef.current?.apply(null, args) : () => curRef.current, []);
|
|
8
9
|
}
|
|
9
10
|
export { useGet };
|
|
10
11
|
//# sourceMappingURL=useGet.mjs.map
|
package/dist/esm/useGet.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["React","useIsomorphicInsertionEffect","useInsertionEffect","useLayoutEffect","useGet","currentValue","initialValue","forwardToFunction","curRef","useRef","current","useCallback","args","apply"],"sources":["../../src/useGet.ts"],"sourcesContent":[null],"mappings":"AAAA,YAAYA,KAAA,MAAW;AAOvB,MAAMC,4BAAA,GAA+BD,KAAA,CAAME,kBAAA,IAAsBF,KAAA,CAAMG,eAAA;AAIhE,SAASC,OACdC,YAAA,EACAC,YAAA,EACAC,iBAAA,EACS;EACT,MAAMC,MAAA,GAASR,KAAA,CAAMS,MAAA,CAAYH,YAAA,IAAgBD,YAAY;EAC7DJ,4BAAA,CAA6B,MAAM;IACjCO,MAAA,CAAOE,OAAA,GAAUL,YAAA;EACnB,CAAC;EAED,OAAOL,KAAA,CAAMW,WAAA,CACXJ,iBAAA,GACI,IAAIK,IAAA,KAASJ,MAAA,CAAOE,OAAA,EAASG,KAAA,CAAM,MAAMD,IAAI,IAC7C,MAAMJ,MAAA,CAAOE,OAAA,EACjB,EACF;AACF","ignoreList":[]}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { useIsomorphicLayoutEffect } from "@tamagui/constants";
|
|
2
1
|
import * as React from "react";
|
|
2
|
+
var useIsomorphicInsertionEffect = React.useInsertionEffect || React.useLayoutEffect;
|
|
3
3
|
function useGet(currentValue, initialValue, forwardToFunction) {
|
|
4
|
-
var curRef = React.useRef(initialValue
|
|
5
|
-
|
|
4
|
+
var curRef = React.useRef(initialValue !== null && initialValue !== void 0 ? initialValue : currentValue);
|
|
5
|
+
useIsomorphicInsertionEffect(function () {
|
|
6
6
|
curRef.current = currentValue;
|
|
7
|
-
})
|
|
8
|
-
|
|
7
|
+
});
|
|
8
|
+
return React.useCallback(forwardToFunction ? function () {
|
|
9
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
10
|
+
args[_key] = arguments[_key];
|
|
11
|
+
}
|
|
9
12
|
var _curRef_current;
|
|
10
13
|
return (_curRef_current = curRef.current) === null || _curRef_current === void 0 ? void 0 : _curRef_current.apply(null, args);
|
|
11
14
|
} : function () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["React","useIsomorphicInsertionEffect","useInsertionEffect","useLayoutEffect","useGet","currentValue","initialValue","forwardToFunction","curRef","useRef","current","useCallback","_len","arguments","length","args","Array","_key","_curRef_current"],"sources":["../../src/useGet.ts"],"sourcesContent":[null],"mappings":"AAAA,YAAYA,KAAA,MAAW;AAOvB,IAAAC,4BAAM,GAAAD,KAA+B,CAAAE,kBAAM,IAAAF,KAAsB,CAAAG,eAAM;AAIhE,SAASC,OACdC,YAAA,EACAC,YAAA,EACAC,iBAAA,EACS;EACT,IAAAC,MAAM,GAAAR,KAAS,CAAAS,MAAM,CAAAH,YAAY,SAAgB,IAAAA,YAAY,cAAAA,YAAA,GAAAD,YAAA;EAC7DJ,4BAAA,CAA6B,YAAM;IACjCO,MAAA,CAAOE,OAAA,GAAUL,YAAA;EACnB,CAAC;EAED,OAAOL,KAAA,CAAMW,WAAA,CAAAJ,iBAAA;IACX,SAAAK,IAAA,GAAAC,SACQ,CAAAC,MAAA,EAASC,IAAA,GAAO,IAAAC,KAAS,CAAAJ,IAAM,GAAAK,IAAM,GAAI,GAAAA,IAC7C,GAAML,IAAA,EAAAK,IAAO;MAChBF,IAAA,CAAAE,IAAA,IAAAJ,SAAA,CAAAI,IAAA;IACH;IACF,IAAAC,eAAA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/use-event",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"files": [
|
|
5
5
|
"src",
|
|
6
6
|
"types",
|
|
@@ -15,15 +15,12 @@
|
|
|
15
15
|
"./package.json": "./package.json",
|
|
16
16
|
".": {
|
|
17
17
|
"types": "./types/index.d.ts",
|
|
18
|
-
"react-native":
|
|
19
|
-
|
|
20
|
-
"import": "./dist/esm/index.native.js",
|
|
21
|
-
"require": "./dist/cjs/index.native.js"
|
|
22
|
-
},
|
|
18
|
+
"react-native": "./dist/esm/index.native.js",
|
|
19
|
+
"browser": "./dist/esm/index.mjs",
|
|
23
20
|
"module": "./dist/esm/index.mjs",
|
|
24
21
|
"import": "./dist/esm/index.mjs",
|
|
25
22
|
"require": "./dist/cjs/index.cjs",
|
|
26
|
-
"default": "./dist/
|
|
23
|
+
"default": "./dist/esm/index.mjs"
|
|
27
24
|
}
|
|
28
25
|
},
|
|
29
26
|
"publishConfig": {
|
|
@@ -35,11 +32,9 @@
|
|
|
35
32
|
"clean": "tamagui-build clean",
|
|
36
33
|
"clean:build": "tamagui-build clean:build"
|
|
37
34
|
},
|
|
38
|
-
"dependencies": {
|
|
39
|
-
"@tamagui/constants": "2.0.0-rc.8"
|
|
40
|
-
},
|
|
35
|
+
"dependencies": {},
|
|
41
36
|
"devDependencies": {
|
|
42
|
-
"@tamagui/build": "2.0.0
|
|
37
|
+
"@tamagui/build": "2.0.0",
|
|
43
38
|
"react": ">=19"
|
|
44
39
|
},
|
|
45
40
|
"peerDependencies": {
|
package/src/useGet.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import { useIsomorphicLayoutEffect } from '@tamagui/constants'
|
|
2
1
|
import * as React from 'react'
|
|
3
2
|
|
|
3
|
+
// useInsertionEffect ensures the ref is updated before any useLayoutEffect
|
|
4
|
+
// reads the returned callback — fixes a React 19 timing issue where a
|
|
5
|
+
// consumer's useLayoutEffect could fire before this ref update, causing stale
|
|
6
|
+
// values. Falls back to useLayoutEffect for React < 18.3. No SSR branch: SSR
|
|
7
|
+
// doesn't run layout effects, so the non-SSR path is correct everywhere.
|
|
8
|
+
const useIsomorphicInsertionEffect = React.useInsertionEffect || React.useLayoutEffect
|
|
9
|
+
|
|
4
10
|
// keeps a reference to the current value easily
|
|
5
11
|
|
|
6
12
|
export function useGet<A>(
|
|
@@ -9,7 +15,7 @@ export function useGet<A>(
|
|
|
9
15
|
forwardToFunction?: boolean
|
|
10
16
|
): () => A {
|
|
11
17
|
const curRef = React.useRef<any>(initialValue ?? currentValue)
|
|
12
|
-
|
|
18
|
+
useIsomorphicInsertionEffect(() => {
|
|
13
19
|
curRef.current = currentValue
|
|
14
20
|
})
|
|
15
21
|
|
package/types/index.d.ts.map
CHANGED
package/types/useEvent.d.ts.map
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
"sources": [
|
|
5
5
|
"src/useEvent.ts"
|
|
6
6
|
],
|
|
7
|
+
"version": 3,
|
|
7
8
|
"sourcesContent": [
|
|
8
9
|
"import { useGet } from './useGet'\n\ntype AnyFunction = (...args: any[]) => any\n\nexport function useEvent<T extends AnyFunction>(callback?: T): T {\n return useGet(callback, defaultValue, true) as T\n}\n\nconst defaultValue = () => {\n throw new Error('Cannot call an event handler while rendering.')\n}\n"
|
|
9
|
-
]
|
|
10
|
-
"version": 3
|
|
10
|
+
]
|
|
11
11
|
}
|
package/types/useGet.d.ts.map
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"mappings": "
|
|
2
|
+
"mappings": "AAWA,OAAO,iBAAS,OAAO,GACrB,cAAc,GACd,oBACA,oCACO",
|
|
3
3
|
"names": [],
|
|
4
4
|
"sources": [
|
|
5
5
|
"src/useGet.ts"
|
|
6
6
|
],
|
|
7
|
+
"version": 3,
|
|
7
8
|
"sourcesContent": [
|
|
8
|
-
"import
|
|
9
|
-
]
|
|
10
|
-
"version": 3
|
|
9
|
+
"import * as React from 'react'\n\n// useInsertionEffect ensures the ref is updated before any useLayoutEffect\n// reads the returned callback — fixes a React 19 timing issue where a\n// consumer's useLayoutEffect could fire before this ref update, causing stale\n// values. Falls back to useLayoutEffect for React < 18.3. No SSR branch: SSR\n// doesn't run layout effects, so the non-SSR path is correct everywhere.\nconst useIsomorphicInsertionEffect = React.useInsertionEffect || React.useLayoutEffect\n\n// keeps a reference to the current value easily\n\nexport function useGet<A>(\n currentValue: A,\n initialValue?: any,\n forwardToFunction?: boolean\n): () => A {\n const curRef = React.useRef<any>(initialValue ?? currentValue)\n useIsomorphicInsertionEffect(() => {\n curRef.current = currentValue\n })\n\n return React.useCallback(\n forwardToFunction\n ? (...args) => curRef.current?.apply(null, args)\n : () => curRef.current,\n []\n )\n}\n"
|
|
10
|
+
]
|
|
11
11
|
}
|
package/dist/cjs/index.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
7
|
-
for (let key of __getOwnPropNames(from))
|
|
8
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
|
-
return to;
|
|
10
|
-
}, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
11
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
12
|
-
var index_exports = {};
|
|
13
|
-
module.exports = __toCommonJS(index_exports);
|
|
14
|
-
__reExport(index_exports, require("./useEvent"), module.exports);
|
|
15
|
-
__reExport(index_exports, require("./useGet"), module.exports);
|
|
16
|
-
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
DELETED
package/dist/cjs/useEvent.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
8
|
-
}, __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
10
|
-
for (let key of __getOwnPropNames(from))
|
|
11
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
|
-
var useEvent_exports = {};
|
|
16
|
-
__export(useEvent_exports, {
|
|
17
|
-
useEvent: () => useEvent
|
|
18
|
-
});
|
|
19
|
-
module.exports = __toCommonJS(useEvent_exports);
|
|
20
|
-
var import_useGet = require("./useGet");
|
|
21
|
-
function useEvent(callback) {
|
|
22
|
-
return (0, import_useGet.useGet)(callback, defaultValue, !0);
|
|
23
|
-
}
|
|
24
|
-
const defaultValue = () => {
|
|
25
|
-
throw new Error("Cannot call an event handler while rendering.");
|
|
26
|
-
};
|
|
27
|
-
//# sourceMappingURL=useEvent.js.map
|
package/dist/cjs/useEvent.js.map
DELETED
package/dist/cjs/useGet.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
-
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
-
return to;
|
|
14
|
-
};
|
|
15
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
21
|
-
mod
|
|
22
|
-
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
23
|
-
var useGet_exports = {};
|
|
24
|
-
__export(useGet_exports, {
|
|
25
|
-
useGet: () => useGet
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(useGet_exports);
|
|
28
|
-
var import_constants = require("@tamagui/constants"), React = __toESM(require("react"), 1);
|
|
29
|
-
function useGet(currentValue, initialValue, forwardToFunction) {
|
|
30
|
-
const curRef = React.useRef(initialValue ?? currentValue);
|
|
31
|
-
return (0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
32
|
-
curRef.current = currentValue;
|
|
33
|
-
}), React.useCallback(
|
|
34
|
-
forwardToFunction ? (...args) => curRef.current?.apply(null, args) : () => curRef.current,
|
|
35
|
-
[]
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=useGet.js.map
|
package/dist/cjs/useGet.js.map
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/useGet.ts"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA0C,+BAC1C,QAAuB;AAIhB,SAAS,OACd,cACA,cACA,mBACS;AACT,QAAM,SAAS,MAAM,OAAY,gBAAgB,YAAY;AAC7D,yDAA0B,MAAM;AAC9B,WAAO,UAAU;AAAA,EACnB,CAAC,GAEM,MAAM;AAAA,IACX,oBACI,IAAI,SAAS,OAAO,SAAS,MAAM,MAAM,IAAI,IAC7C,MAAM,OAAO;AAAA,IACjB,CAAC;AAAA,EACH;AACF;",
|
|
5
|
-
"names": []
|
|
6
|
-
}
|
package/dist/esm/useEvent.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { useGet } from "./useGet";
|
|
2
|
-
function useEvent(callback) {
|
|
3
|
-
return useGet(callback, defaultValue, !0);
|
|
4
|
-
}
|
|
5
|
-
const defaultValue = () => {
|
|
6
|
-
throw new Error("Cannot call an event handler while rendering.");
|
|
7
|
-
};
|
|
8
|
-
export {
|
|
9
|
-
useEvent
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=useEvent.js.map
|
package/dist/esm/useEvent.js.map
DELETED
package/dist/esm/useGet.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { useIsomorphicLayoutEffect } from "@tamagui/constants";
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
function useGet(currentValue, initialValue, forwardToFunction) {
|
|
4
|
-
const curRef = React.useRef(initialValue ?? currentValue);
|
|
5
|
-
return useIsomorphicLayoutEffect(() => {
|
|
6
|
-
curRef.current = currentValue;
|
|
7
|
-
}), React.useCallback(
|
|
8
|
-
forwardToFunction ? (...args) => curRef.current?.apply(null, args) : () => curRef.current,
|
|
9
|
-
[]
|
|
10
|
-
);
|
|
11
|
-
}
|
|
12
|
-
export {
|
|
13
|
-
useGet
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=useGet.js.map
|
package/dist/esm/useGet.js.map
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/useGet.ts"],
|
|
4
|
-
"mappings": "AAAA,SAAS,iCAAiC;AAC1C,YAAY,WAAW;AAIhB,SAAS,OACd,cACA,cACA,mBACS;AACT,QAAM,SAAS,MAAM,OAAY,gBAAgB,YAAY;AAC7D,mCAA0B,MAAM;AAC9B,WAAO,UAAU;AAAA,EACnB,CAAC,GAEM,MAAM;AAAA,IACX,oBACI,IAAI,SAAS,OAAO,SAAS,MAAM,MAAM,IAAI,IAC7C,MAAM,OAAO;AAAA,IACjB,CAAC;AAAA,EACH;AACF;",
|
|
5
|
-
"names": []
|
|
6
|
-
}
|