@ember-data/tracking 4.8.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/LICENSE.md ADDED
@@ -0,0 +1,11 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (C) 2017-2022 Ember.js contributors
4
+ Portions Copyright (C) 2011-2017 Tilde, Inc. and contributors.
5
+ Portions Copyright (C) 2011 LivingSocial Inc.
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,13 @@
1
+ @ember-data/tracking
2
+ ============================================================================
3
+
4
+ Tracking Primitives for controlling change notification of Tracked properties when working with EmberData
5
+
6
+ > Note: This is a V2 Addon, but we have intentionally configured it to act and report as a V1 Addon due
7
+ to bugs with ember-auto-import.
8
+ >
9
+ > We can remove the V1 tag if ember-auto-import will no longer attempt
10
+ to load V2 addons or if it is fixed to work with V1 addons with custom addon trees and also dedupes modules for test apps.
11
+ >
12
+ > You can still consume this as a normal library.
13
+ > In other projects.
package/addon-main.js ADDED
@@ -0,0 +1,34 @@
1
+ const path = require('path');
2
+
3
+ const Funnel = require('broccoli-funnel');
4
+
5
+ module.exports = {
6
+ name: require('./package.json').name,
7
+
8
+ options: {
9
+ babel: {
10
+ plugins: [require.resolve('./lib/transform-ext.js')],
11
+ },
12
+ },
13
+
14
+ treeForAddon() {
15
+ const assetDir = path.join(__dirname, './dist');
16
+ return this._super.treeForAddon.call(this, new Funnel(assetDir, { include: ['**/*.js'] }));
17
+ },
18
+
19
+ treeForVendor() {
20
+ return;
21
+ },
22
+ treeForPublic() {
23
+ return;
24
+ },
25
+ treeForStyles() {
26
+ return;
27
+ },
28
+ treeForAddonStyles() {
29
+ return;
30
+ },
31
+ treeForApp() {
32
+ return;
33
+ },
34
+ };
@@ -0,0 +1,120 @@
1
+ /**
2
+ * @module @ember-data/tracking
3
+ */
4
+
5
+ let TRANSACTION = null;
6
+ function createTransaction() {
7
+ let transaction = {
8
+ cbs: new Set(),
9
+ props: new Set(),
10
+ sub: new Set(),
11
+ parent: null
12
+ };
13
+ if (TRANSACTION) {
14
+ transaction.parent = TRANSACTION;
15
+ }
16
+ TRANSACTION = transaction;
17
+ }
18
+ function subscribe(obj) {
19
+ if (TRANSACTION) {
20
+ TRANSACTION.sub.add(obj);
21
+ } else {
22
+ obj.ref;
23
+ }
24
+ }
25
+ function flushTransaction() {
26
+ let transaction = TRANSACTION;
27
+ TRANSACTION = transaction.parent;
28
+ transaction.cbs.forEach(cb => {
29
+ cb();
30
+ });
31
+ transaction.props.forEach(obj => {
32
+ obj.t = true;
33
+ obj.ref = null;
34
+ });
35
+ transaction.sub.forEach(obj => {
36
+ obj.ref;
37
+ });
38
+ }
39
+ async function untrack() {
40
+ let transaction = TRANSACTION;
41
+ TRANSACTION = transaction.parent;
42
+
43
+ // defer writes
44
+ await Promise.resolve();
45
+ transaction.cbs.forEach(cb => {
46
+ cb();
47
+ });
48
+ transaction.props.forEach(obj => {
49
+ obj.t = true;
50
+ obj.ref = null;
51
+ });
52
+ }
53
+ function addToTransaction(obj) {
54
+ if (TRANSACTION) {
55
+ TRANSACTION.props.add(obj);
56
+ } else {
57
+ obj.ref = null;
58
+ }
59
+ }
60
+ function addTransactionCB(method) {
61
+ if (TRANSACTION) {
62
+ TRANSACTION.cbs.add(method);
63
+ } else {
64
+ method();
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Run `method` without subscribing to any tracked properties
70
+ * controlled by EmberData.
71
+ *
72
+ * This should rarely be used except by libraries that really
73
+ * know what they are doing. It is most useful for wrapping
74
+ * certain kinds of fetch/query logic from within a `Resource`
75
+ * `hook` or other similar pattern.
76
+ *
77
+ * @function untracked
78
+ * @public
79
+ * @param method
80
+ * @returns result of invoking method
81
+ */
82
+ function untracked(method) {
83
+ createTransaction();
84
+ const ret = method();
85
+ void untrack();
86
+ return ret;
87
+ }
88
+
89
+ /**
90
+ *
91
+ * @function transact
92
+ * @public
93
+ * @param method
94
+ * @returns result of invoking method
95
+ */
96
+ function transact(method) {
97
+ createTransaction();
98
+ const ret = method();
99
+ flushTransaction();
100
+ return ret;
101
+ }
102
+
103
+ /**
104
+ *
105
+ * @method memoTransact
106
+ * @public
107
+ * @param method
108
+ * @returns a function that will invoke method in a transaction with any provided args and return its result
109
+ */
110
+ function memoTransact(method) {
111
+ return function (...args) {
112
+ createTransaction();
113
+ const ret = method(...args);
114
+ flushTransaction();
115
+ return ret;
116
+ };
117
+ }
118
+
119
+ export { addToTransaction, addTransactionCB, memoTransact, subscribe, transact, untracked };
120
+ //# sourceMappingURL=-private.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"-private.js","sources":["../src/-private.ts"],"sourcesContent":["/**\n * @module @ember-data/tracking\n */\ntype OpaqueFn = (...args: unknown[]) => unknown;\ntype Tag = { ref: null; t: boolean };\ntype Transaction = {\n cbs: Set<OpaqueFn>;\n props: Set<Tag>;\n sub: Set<Tag>;\n parent: Transaction | null;\n};\nlet TRANSACTION: Transaction | null = null;\n\nfunction createTransaction() {\n let transaction: Transaction = {\n cbs: new Set(),\n props: new Set(),\n sub: new Set(),\n parent: null,\n };\n if (TRANSACTION) {\n transaction.parent = TRANSACTION;\n }\n TRANSACTION = transaction;\n}\n\nexport function subscribe(obj: Tag): void {\n if (TRANSACTION) {\n TRANSACTION.sub.add(obj);\n } else {\n obj.ref;\n }\n}\n\nfunction flushTransaction() {\n let transaction = TRANSACTION!;\n TRANSACTION = transaction.parent;\n transaction.cbs.forEach((cb) => {\n cb();\n });\n transaction.props.forEach((obj: Tag) => {\n obj.t = true;\n obj.ref = null;\n });\n transaction.sub.forEach((obj: Tag) => {\n obj.ref;\n });\n}\nasync function untrack() {\n let transaction = TRANSACTION!;\n TRANSACTION = transaction.parent;\n\n // defer writes\n await Promise.resolve();\n transaction.cbs.forEach((cb) => {\n cb();\n });\n transaction.props.forEach((obj: Tag) => {\n obj.t = true;\n obj.ref = null;\n });\n}\n\nexport function addToTransaction(obj: Tag): void {\n if (TRANSACTION) {\n TRANSACTION.props.add(obj);\n } else {\n obj.ref = null;\n }\n}\nexport function addTransactionCB(method: OpaqueFn): void {\n if (TRANSACTION) {\n TRANSACTION.cbs.add(method);\n } else {\n method();\n }\n}\n\n/**\n * Run `method` without subscribing to any tracked properties\n * controlled by EmberData.\n *\n * This should rarely be used except by libraries that really\n * know what they are doing. It is most useful for wrapping\n * certain kinds of fetch/query logic from within a `Resource`\n * `hook` or other similar pattern.\n *\n * @function untracked\n * @public\n * @param method\n * @returns result of invoking method\n */\nexport function untracked<T extends OpaqueFn>(method: T): ReturnType<T> {\n createTransaction();\n const ret = method();\n void untrack();\n return ret as ReturnType<T>;\n}\n\n/**\n *\n * @function transact\n * @public\n * @param method\n * @returns result of invoking method\n */\nexport function transact<T extends OpaqueFn>(method: T): ReturnType<T> {\n createTransaction();\n const ret = method();\n flushTransaction();\n return ret as ReturnType<T>;\n}\n\n/**\n *\n * @method memoTransact\n * @public\n * @param method\n * @returns a function that will invoke method in a transaction with any provided args and return its result\n */\nexport function memoTransact<T extends OpaqueFn>(method: T): (...args: unknown[]) => ReturnType<T> {\n return function (...args: unknown[]) {\n createTransaction();\n const ret = method(...args);\n flushTransaction();\n return ret as ReturnType<T>;\n };\n}\n"],"names":["TRANSACTION","createTransaction","transaction","cbs","Set","props","sub","parent","subscribe","obj","add","ref","flushTransaction","forEach","cb","t","untrack","Promise","resolve","addToTransaction","addTransactionCB","method","untracked","ret","transact","memoTransact","args"],"mappings":"AAAA;AACA;AACA;;AASA,IAAIA,WAA+B,GAAG,IAAI,CAAA;AAE1C,SAASC,iBAAiB,GAAG;AAC3B,EAAA,IAAIC,WAAwB,GAAG;IAC7BC,GAAG,EAAE,IAAIC,GAAG,EAAE;IACdC,KAAK,EAAE,IAAID,GAAG,EAAE;IAChBE,GAAG,EAAE,IAAIF,GAAG,EAAE;AACdG,IAAAA,MAAM,EAAE,IAAA;GACT,CAAA;AACD,EAAA,IAAIP,WAAW,EAAE;IACfE,WAAW,CAACK,MAAM,GAAGP,WAAW,CAAA;AAClC,GAAA;AACAA,EAAAA,WAAW,GAAGE,WAAW,CAAA;AAC3B,CAAA;AAEO,SAASM,SAAS,CAACC,GAAQ,EAAQ;AACxC,EAAA,IAAIT,WAAW,EAAE;AACfA,IAAAA,WAAW,CAACM,GAAG,CAACI,GAAG,CAACD,GAAG,CAAC,CAAA;AAC1B,GAAC,MAAM;AACLA,IAAAA,GAAG,CAACE,GAAG,CAAA;AACT,GAAA;AACF,CAAA;AAEA,SAASC,gBAAgB,GAAG;EAC1B,IAAIV,WAAW,GAAGF,WAAY,CAAA;EAC9BA,WAAW,GAAGE,WAAW,CAACK,MAAM,CAAA;AAChCL,EAAAA,WAAW,CAACC,GAAG,CAACU,OAAO,CAAEC,EAAE,IAAK;AAC9BA,IAAAA,EAAE,EAAE,CAAA;AACN,GAAC,CAAC,CAAA;AACFZ,EAAAA,WAAW,CAACG,KAAK,CAACQ,OAAO,CAAEJ,GAAQ,IAAK;IACtCA,GAAG,CAACM,CAAC,GAAG,IAAI,CAAA;IACZN,GAAG,CAACE,GAAG,GAA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,MAAMsB,GAAG,GAAGF,MAAM,EAAE,CAAA;AACpB,EAAA,KAAKL,OAAO,EAAE,CAAA;AACd,EAAA,OAAOO,GAAG,CAAA;AACZ,CAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,QAAQ,CAAqBH,MAAS,EAAiB;AACrEpB,EAAAA,iBAAiB,EAAE,CAAA;EACnB,MAAMsB,GAAG,GAAGF,MAAM,EAAE,CAAA;AACpBT,EAAAA,gBAAgB,EAAE,CAAA;AAClB,EAAA,OAAOW,GAAG,CAAA;AACZ,CAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,YAAY,CAAqBJ,MAAS,EAAyC;EACjG,OAAO,UAAU,GAAGK,IAAe,EAAE;AACnCzB,IAAAA,iBAAiB,EAAE,CAAA;AACnB,IAAA,MAAMsB,GAAG,GAAGF,MAAM,CAAC,GAAGK,IAAI,CAAC,CAAA;AAC3Bd,IAAAA,gBAAgB,EAAE,CAAA;AAClB,IAAA,OAAOW,GAAG,CAAA;GACX,CAAA;AACH;;;;"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { memoTransact, transact, untracked } from './-private.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,16 @@
1
+ module.exports = function () {
2
+ return {
3
+ name: '@ember-data/v1-addon-shim/transform-ext',
4
+ visitor: {
5
+ Program(path) {
6
+ path.node.body.forEach((node) => {
7
+ if (node.type === 'ImportDeclaration' || (node.type === 'ExportNamedDeclaration' && node.source)) {
8
+ if (node.source.value.endsWith('.js')) {
9
+ node.source.value = node.source.value.replace('.js', '');
10
+ }
11
+ }
12
+ });
13
+ },
14
+ },
15
+ };
16
+ };
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@ember-data/tracking",
3
+ "description": "Tracking Primitives for controlling change notification of Tracked properties when working with EmberData",
4
+ "version": "4.8.0",
5
+ "private": false,
6
+ "license": "MIT",
7
+ "author": "Chris Thoburn <runspired@users.noreply.github.com>",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+ssh://git@github.com:emberjs/data.git",
11
+ "directory": "addons/tracking"
12
+ },
13
+ "homepage": "https://github.com/emberjs/data",
14
+ "bugs": "https://github.com/emberjs/data/issues",
15
+ "engines": {
16
+ "node": "14.* || 16.* || >= 18"
17
+ },
18
+ "keywords": [
19
+ "ember-addon"
20
+ ],
21
+ "volta": {
22
+ "extends": "../../package.json"
23
+ },
24
+ "dependencies": {
25
+ "broccoli-funnel": "^3.0.8",
26
+ "ember-cli-babel": "^7.26.11"
27
+ },
28
+ "exports": {
29
+ ".": "./dist/index.js",
30
+ "./*": "./dist/*",
31
+ "./addon-main.js": "./addon-main.js"
32
+ },
33
+ "files": [
34
+ "lib",
35
+ "addon-main.js",
36
+ "dist"
37
+ ],
38
+ "scripts": {
39
+ "build": "rollup --config",
40
+ "start": "rollup --config --watch",
41
+ "prepack": "rollup --config"
42
+ },
43
+ "ember-addon": {
44
+ "main": "addon-main.js",
45
+ "type": "addon",
46
+ "version": 1
47
+ },
48
+ "devDependencies": {
49
+ "@babel/core": "^7.19.6",
50
+ "@babel/plugin-proposal-class-properties": "^7.18.6",
51
+ "@babel/plugin-proposal-decorators": "^7.20.0",
52
+ "@babel/plugin-transform-runtime": "^7.19.6",
53
+ "@babel/plugin-transform-typescript": "^7.20.0",
54
+ "@babel/preset-env": "^7.19.4",
55
+ "@babel/preset-typescript": "^7.18.6",
56
+ "@babel/runtime": "^7.20.0",
57
+ "@embroider/addon-dev": "^2.0.0",
58
+ "@rollup/plugin-babel": "^6.0.2",
59
+ "@rollup/plugin-node-resolve": "^15.0.1",
60
+ "rollup": "^3.2.3",
61
+ "tslib": "^2.4.0",
62
+ "typescript": "^4.8.4",
63
+ "walk-sync": "^3.0.0"
64
+ },
65
+ "ember": {
66
+ "edition": "octane"
67
+ }
68
+ }