@ngrx/signals 17.0.0-beta.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 +25 -0
- package/README.md +3 -0
- package/esm2022/index.mjs +2 -0
- package/esm2022/ngrx-signals.mjs +5 -0
- package/esm2022/rxjs-interop/index.mjs +2 -0
- package/esm2022/rxjs-interop/ngrx-signals-rxjs-interop.mjs +5 -0
- package/esm2022/rxjs-interop/src/index.mjs +2 -0
- package/esm2022/rxjs-interop/src/rx-method.mjs +31 -0
- package/esm2022/src/deep-signal.mjs +22 -0
- package/esm2022/src/helpers.mjs +4 -0
- package/esm2022/src/index.mjs +9 -0
- package/esm2022/src/patch-state.mjs +8 -0
- package/esm2022/src/signal-state.mjs +12 -0
- package/esm2022/src/signal-store-feature.mjs +10 -0
- package/esm2022/src/signal-store-models.mjs +2 -0
- package/esm2022/src/signal-store.mjs +47 -0
- package/esm2022/src/ts-helpers.mjs +2 -0
- package/esm2022/src/with-computed.mjs +16 -0
- package/esm2022/src/with-hooks.mjs +30 -0
- package/esm2022/src/with-methods.mjs +22 -0
- package/esm2022/src/with-state.mjs +27 -0
- package/fesm2022/ngrx-signals-rxjs-interop.mjs +38 -0
- package/fesm2022/ngrx-signals-rxjs-interop.mjs.map +1 -0
- package/fesm2022/ngrx-signals.mjs +192 -0
- package/fesm2022/ngrx-signals.mjs.map +1 -0
- package/index.d.ts +1 -0
- package/migrations/migration.json +4 -0
- package/package.json +72 -0
- package/rxjs-interop/index.d.ts +1 -0
- package/rxjs-interop/src/index.d.ts +1 -0
- package/rxjs-interop/src/rx-method.d.ts +8 -0
- package/schematics/collection.json +10 -0
- package/schematics/ng-add/index.js +21 -0
- package/schematics/ng-add/index.js.map +1 -0
- package/schematics/ng-add/schema.js +3 -0
- package/schematics/ng-add/schema.js.map +1 -0
- package/schematics/ng-add/schema.json +14 -0
- package/schematics-core/index.js +77 -0
- package/schematics-core/index.js.map +1 -0
- package/schematics-core/utility/ast-utils.js +705 -0
- package/schematics-core/utility/ast-utils.js.map +1 -0
- package/schematics-core/utility/change.js +162 -0
- package/schematics-core/utility/change.js.map +1 -0
- package/schematics-core/utility/config.js +21 -0
- package/schematics-core/utility/config.js.map +1 -0
- package/schematics-core/utility/find-component.js +101 -0
- package/schematics-core/utility/find-component.js.map +1 -0
- package/schematics-core/utility/find-module.js +102 -0
- package/schematics-core/utility/find-module.js.map +1 -0
- package/schematics-core/utility/json-utilts.js +37 -0
- package/schematics-core/utility/json-utilts.js.map +1 -0
- package/schematics-core/utility/libs-version.js +5 -0
- package/schematics-core/utility/libs-version.js.map +1 -0
- package/schematics-core/utility/ngrx-utils.js +248 -0
- package/schematics-core/utility/ngrx-utils.js.map +1 -0
- package/schematics-core/utility/package.js +23 -0
- package/schematics-core/utility/package.js.map +1 -0
- package/schematics-core/utility/parse-name.js +14 -0
- package/schematics-core/utility/parse-name.js.map +1 -0
- package/schematics-core/utility/project.js +48 -0
- package/schematics-core/utility/project.js.map +1 -0
- package/schematics-core/utility/strings.js +138 -0
- package/schematics-core/utility/strings.js.map +1 -0
- package/schematics-core/utility/update.js +34 -0
- package/schematics-core/utility/update.js.map +1 -0
- package/schematics-core/utility/visitors.js +250 -0
- package/schematics-core/utility/visitors.js.map +1 -0
- package/src/deep-signal.d.ts +6 -0
- package/src/helpers.d.ts +1 -0
- package/src/index.d.ts +8 -0
- package/src/patch-state.d.ts +3 -0
- package/src/signal-state.d.ts +11 -0
- package/src/signal-store-feature.d.ts +22 -0
- package/src/signal-store-models.d.ts +49 -0
- package/src/signal-store.d.ts +21 -0
- package/src/ts-helpers.d.ts +11 -0
- package/src/with-computed.d.ts +5 -0
- package/src/with-hooks.d.ts +9 -0
- package/src/with-methods.d.ts +6 -0
- package/src/with-state.d.ts +10 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
3
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
4
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
5
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
6
|
+
function step(op) {
|
|
7
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
8
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
9
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
10
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
11
|
+
switch (op[0]) {
|
|
12
|
+
case 0: case 1: t = op; break;
|
|
13
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
14
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
15
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
16
|
+
default:
|
|
17
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
18
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
19
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
20
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
21
|
+
if (t[2]) _.ops.pop();
|
|
22
|
+
_.trys.pop(); continue;
|
|
23
|
+
}
|
|
24
|
+
op = body.call(thisArg, _);
|
|
25
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
26
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var __values = (this && this.__values) || function(o) {
|
|
30
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
31
|
+
if (m) return m.call(o);
|
|
32
|
+
if (o && typeof o.length === "number") return {
|
|
33
|
+
next: function () {
|
|
34
|
+
if (o && i >= o.length) o = void 0;
|
|
35
|
+
return { value: o && o[i++], done: !o };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
39
|
+
};
|
|
40
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
41
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
42
|
+
if (!m) return o;
|
|
43
|
+
var i = m.call(o), r, ar = [], e;
|
|
44
|
+
try {
|
|
45
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
46
|
+
}
|
|
47
|
+
catch (error) { e = { error: error }; }
|
|
48
|
+
finally {
|
|
49
|
+
try {
|
|
50
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
51
|
+
}
|
|
52
|
+
finally { if (e) throw e.error; }
|
|
53
|
+
}
|
|
54
|
+
return ar;
|
|
55
|
+
};
|
|
56
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
+
exports.visitDecorator = exports.visitNgModules = exports.visitComponents = exports.visitNgModuleExports = exports.visitNgModuleImports = exports.visitTemplates = exports.visitTSSourceFiles = void 0;
|
|
58
|
+
var ts = require("typescript");
|
|
59
|
+
var core_1 = require("@angular-devkit/core");
|
|
60
|
+
function visitTSSourceFiles(tree, visitor) {
|
|
61
|
+
var e_1, _a;
|
|
62
|
+
var result = undefined;
|
|
63
|
+
try {
|
|
64
|
+
for (var _b = __values(visit(tree.root)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
65
|
+
var sourceFile = _c.value;
|
|
66
|
+
result = visitor(sourceFile, tree, result);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
70
|
+
finally {
|
|
71
|
+
try {
|
|
72
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
73
|
+
}
|
|
74
|
+
finally { if (e_1) throw e_1.error; }
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
exports.visitTSSourceFiles = visitTSSourceFiles;
|
|
79
|
+
function visitTemplates(tree, visitor) {
|
|
80
|
+
visitTSSourceFiles(tree, function (source) {
|
|
81
|
+
visitComponents(source, function (_, decoratorExpressionNode) {
|
|
82
|
+
ts.forEachChild(decoratorExpressionNode, function findTemplates(n) {
|
|
83
|
+
if (ts.isPropertyAssignment(n) && ts.isIdentifier(n.name)) {
|
|
84
|
+
if (n.name.text === 'template' &&
|
|
85
|
+
ts.isStringLiteralLike(n.initializer)) {
|
|
86
|
+
// Need to add an offset of one to the start because the template quotes are
|
|
87
|
+
// not part of the template content.
|
|
88
|
+
var templateStartIdx = n.initializer.getStart() + 1;
|
|
89
|
+
visitor({
|
|
90
|
+
fileName: source.fileName,
|
|
91
|
+
content: n.initializer.text,
|
|
92
|
+
inline: true,
|
|
93
|
+
start: templateStartIdx,
|
|
94
|
+
}, tree);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
else if (n.name.text === 'templateUrl' &&
|
|
98
|
+
ts.isStringLiteralLike(n.initializer)) {
|
|
99
|
+
var parts = (0, core_1.normalize)(source.fileName).split('/').slice(0, -1);
|
|
100
|
+
var templatePath = (0, core_1.resolve)((0, core_1.normalize)(parts.join('/')), (0, core_1.normalize)(n.initializer.text));
|
|
101
|
+
if (!tree.exists(templatePath)) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
var fileContent = tree.read(templatePath);
|
|
105
|
+
if (!fileContent) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
visitor({
|
|
109
|
+
fileName: templatePath,
|
|
110
|
+
content: fileContent.toString(),
|
|
111
|
+
inline: false,
|
|
112
|
+
start: 0,
|
|
113
|
+
}, tree);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
ts.forEachChild(n, findTemplates);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
exports.visitTemplates = visitTemplates;
|
|
123
|
+
function visitNgModuleImports(sourceFile, callback) {
|
|
124
|
+
visitNgModuleProperty(sourceFile, callback, 'imports');
|
|
125
|
+
}
|
|
126
|
+
exports.visitNgModuleImports = visitNgModuleImports;
|
|
127
|
+
function visitNgModuleExports(sourceFile, callback) {
|
|
128
|
+
visitNgModuleProperty(sourceFile, callback, 'exports');
|
|
129
|
+
}
|
|
130
|
+
exports.visitNgModuleExports = visitNgModuleExports;
|
|
131
|
+
function visitNgModuleProperty(sourceFile, callback, property) {
|
|
132
|
+
visitNgModules(sourceFile, function (_, decoratorExpressionNode) {
|
|
133
|
+
ts.forEachChild(decoratorExpressionNode, function findTemplates(n) {
|
|
134
|
+
if (ts.isPropertyAssignment(n) &&
|
|
135
|
+
ts.isIdentifier(n.name) &&
|
|
136
|
+
n.name.text === property &&
|
|
137
|
+
ts.isArrayLiteralExpression(n.initializer)) {
|
|
138
|
+
callback(n, n.initializer.elements);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
ts.forEachChild(n, findTemplates);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function visitComponents(sourceFile, callback) {
|
|
146
|
+
visitDecorator(sourceFile, 'Component', callback);
|
|
147
|
+
}
|
|
148
|
+
exports.visitComponents = visitComponents;
|
|
149
|
+
function visitNgModules(sourceFile, callback) {
|
|
150
|
+
visitDecorator(sourceFile, 'NgModule', callback);
|
|
151
|
+
}
|
|
152
|
+
exports.visitNgModules = visitNgModules;
|
|
153
|
+
function visitDecorator(sourceFile, decoratorName, callback) {
|
|
154
|
+
ts.forEachChild(sourceFile, function findClassDeclaration(node) {
|
|
155
|
+
if (!ts.isClassDeclaration(node)) {
|
|
156
|
+
ts.forEachChild(node, findClassDeclaration);
|
|
157
|
+
}
|
|
158
|
+
var classDeclarationNode = node;
|
|
159
|
+
var decorators = ts.getDecorators(classDeclarationNode);
|
|
160
|
+
if (!decorators || !decorators.length) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
var componentDecorator = decorators.find(function (d) {
|
|
164
|
+
return (ts.isCallExpression(d.expression) &&
|
|
165
|
+
ts.isIdentifier(d.expression.expression) &&
|
|
166
|
+
d.expression.expression.text === decoratorName);
|
|
167
|
+
});
|
|
168
|
+
if (!componentDecorator) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
var expression = componentDecorator.expression;
|
|
172
|
+
if (!ts.isCallExpression(expression)) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
var _a = __read(expression.arguments, 1), arg = _a[0];
|
|
176
|
+
if (!arg || !ts.isObjectLiteralExpression(arg)) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
callback(classDeclarationNode, arg);
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
exports.visitDecorator = visitDecorator;
|
|
183
|
+
function visit(directory) {
|
|
184
|
+
var _a, _b, path, entry, content, source, e_2_1, _c, _d, path, e_3_1;
|
|
185
|
+
var e_2, _e, e_3, _f;
|
|
186
|
+
return __generator(this, function (_g) {
|
|
187
|
+
switch (_g.label) {
|
|
188
|
+
case 0:
|
|
189
|
+
_g.trys.push([0, 5, 6, 7]);
|
|
190
|
+
_a = __values(directory.subfiles), _b = _a.next();
|
|
191
|
+
_g.label = 1;
|
|
192
|
+
case 1:
|
|
193
|
+
if (!!_b.done) return [3 /*break*/, 4];
|
|
194
|
+
path = _b.value;
|
|
195
|
+
if (!(path.endsWith('.ts') && !path.endsWith('.d.ts'))) return [3 /*break*/, 3];
|
|
196
|
+
entry = directory.file(path);
|
|
197
|
+
if (!entry) return [3 /*break*/, 3];
|
|
198
|
+
content = entry.content;
|
|
199
|
+
source = ts.createSourceFile(entry.path, content.toString().replace(/^\uFEFF/, ''), ts.ScriptTarget.Latest, true);
|
|
200
|
+
return [4 /*yield*/, source];
|
|
201
|
+
case 2:
|
|
202
|
+
_g.sent();
|
|
203
|
+
_g.label = 3;
|
|
204
|
+
case 3:
|
|
205
|
+
_b = _a.next();
|
|
206
|
+
return [3 /*break*/, 1];
|
|
207
|
+
case 4: return [3 /*break*/, 7];
|
|
208
|
+
case 5:
|
|
209
|
+
e_2_1 = _g.sent();
|
|
210
|
+
e_2 = { error: e_2_1 };
|
|
211
|
+
return [3 /*break*/, 7];
|
|
212
|
+
case 6:
|
|
213
|
+
try {
|
|
214
|
+
if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
|
|
215
|
+
}
|
|
216
|
+
finally { if (e_2) throw e_2.error; }
|
|
217
|
+
return [7 /*endfinally*/];
|
|
218
|
+
case 7:
|
|
219
|
+
_g.trys.push([7, 12, 13, 14]);
|
|
220
|
+
_c = __values(directory.subdirs), _d = _c.next();
|
|
221
|
+
_g.label = 8;
|
|
222
|
+
case 8:
|
|
223
|
+
if (!!_d.done) return [3 /*break*/, 11];
|
|
224
|
+
path = _d.value;
|
|
225
|
+
if (path === 'node_modules') {
|
|
226
|
+
return [3 /*break*/, 10];
|
|
227
|
+
}
|
|
228
|
+
return [5 /*yield**/, __values(visit(directory.dir(path)))];
|
|
229
|
+
case 9:
|
|
230
|
+
_g.sent();
|
|
231
|
+
_g.label = 10;
|
|
232
|
+
case 10:
|
|
233
|
+
_d = _c.next();
|
|
234
|
+
return [3 /*break*/, 8];
|
|
235
|
+
case 11: return [3 /*break*/, 14];
|
|
236
|
+
case 12:
|
|
237
|
+
e_3_1 = _g.sent();
|
|
238
|
+
e_3 = { error: e_3_1 };
|
|
239
|
+
return [3 /*break*/, 14];
|
|
240
|
+
case 13:
|
|
241
|
+
try {
|
|
242
|
+
if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
|
|
243
|
+
}
|
|
244
|
+
finally { if (e_3) throw e_3.error; }
|
|
245
|
+
return [7 /*endfinally*/];
|
|
246
|
+
case 14: return [2 /*return*/];
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
//# sourceMappingURL=visitors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visitors.js","sourceRoot":"","sources":["../../../../../modules/signals/schematics-core/utility/visitors.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAiC;AACjC,6CAA0D;AAG1D,SAAgB,kBAAkB,CAChC,IAAU,EACV,OAIuB;;IAEvB,IAAI,MAAM,GAAuB,SAAS,CAAC;;QAC3C,KAAyB,IAAA,KAAA,SAAA,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA,gBAAA,4BAAE;YAAtC,IAAM,UAAU,WAAA;YACnB,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;SAC5C;;;;;;;;;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAdD,gDAcC;AAED,SAAgB,cAAc,CAC5B,IAAU,EACV,OAQS;IAET,kBAAkB,CAAC,IAAI,EAAE,UAAC,MAAM;QAC9B,eAAe,CAAC,MAAM,EAAE,UAAC,CAAC,EAAE,uBAAuB;YACjD,EAAE,CAAC,YAAY,CAAC,uBAAuB,EAAE,SAAS,aAAa,CAAC,CAAC;gBAC/D,IAAI,EAAE,CAAC,oBAAoB,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE;oBACzD,IACE,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,UAAU;wBAC1B,EAAE,CAAC,mBAAmB,CAAC,CAAC,CAAC,WAAW,CAAC,EACrC;wBACA,4EAA4E;wBAC5E,oCAAoC;wBACpC,IAAM,gBAAgB,GAAG,CAAC,CAAC,WAAW,CAAC,QAAQ,EAAE,GAAG,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I,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA,EAA/C,wBAA+C;gBAC3C,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;qBAC/B,KAAK,EAAL,wBAAK;gBACD,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;gBACxB,MAAM,GAAG,EAAE,CAAC,gBAAgB,CAChC,KAAK,CAAC,IAAI,EACV,OAAO,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,EACzC,EAAE,CAAC,YAAY,CAAC,MAAM,EACtB,IAAI,CACL,CAAC;gBACF,qBAAM,MAAM,EAAA;;gBAAZ,SAAY,CAAC;;;;;;;;;;;;;;;;;;gBAKA,KAAA,SAAA,SAAS,CAAC,OAAO,CAAA;;;;gBAAzB,IAAI;gBACb,IAAI,IAAI,KAAK,cAAc,EAAE;oBAC3B,yBAAS;iBACV;gBAED,sBAAA,SAAO,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAA,EAAA;;gBAAjC,SAAiC,CAAC;;;;;;;;;;;;;;;;;;;CAErC","sourcesContent":["import * as ts from 'typescript';\nimport { normalize, resolve } from '@angular-devkit/core';\nimport { Tree, DirEntry } from '@angular-devkit/schematics';\n\nexport function visitTSSourceFiles<Result = void>(\n tree: Tree,\n visitor: (\n sourceFile: ts.SourceFile,\n tree: Tree,\n result?: Result\n ) => Result | undefined\n): Result | undefined {\n let result: Result | undefined = undefined;\n for (const sourceFile of visit(tree.root)) {\n result = visitor(sourceFile, tree, result);\n }\n\n return result;\n}\n\nexport function visitTemplates(\n tree: Tree,\n visitor: (\n template: {\n fileName: string;\n content: string;\n inline: boolean;\n start: number;\n },\n tree: Tree\n ) => void\n): void {\n visitTSSourceFiles(tree, (source) => {\n visitComponents(source, (_, decoratorExpressionNode) => {\n ts.forEachChild(decoratorExpressionNode, function findTemplates(n) {\n if (ts.isPropertyAssignment(n) && ts.isIdentifier(n.name)) {\n if (\n n.name.text === 'template' &&\n ts.isStringLiteralLike(n.initializer)\n ) {\n // Need to add an offset of one to the start because the template quotes are\n // not part of the template content.\n const templateStartIdx = n.initializer.getStart() + 1;\n visitor(\n {\n fileName: source.fileName,\n content: n.initializer.text,\n inline: true,\n start: templateStartIdx,\n },\n tree\n );\n return;\n } else if (\n n.name.text === 'templateUrl' &&\n ts.isStringLiteralLike(n.initializer)\n ) {\n const parts = normalize(source.fileName).split('/').slice(0, -1);\n const templatePath = resolve(\n normalize(parts.join('/')),\n normalize(n.initializer.text)\n );\n if (!tree.exists(templatePath)) {\n return;\n }\n\n const fileContent = tree.read(templatePath);\n if (!fileContent) {\n return;\n }\n\n visitor(\n {\n fileName: templatePath,\n content: fileContent.toString(),\n inline: false,\n start: 0,\n },\n tree\n );\n return;\n }\n }\n\n ts.forEachChild(n, findTemplates);\n });\n });\n });\n}\n\nexport function visitNgModuleImports(\n sourceFile: ts.SourceFile,\n callback: (\n importNode: ts.PropertyAssignment,\n elementExpressions: ts.NodeArray<ts.Expression>\n ) => void\n) {\n visitNgModuleProperty(sourceFile, callback, 'imports');\n}\n\nexport function visitNgModuleExports(\n sourceFile: ts.SourceFile,\n callback: (\n exportNode: ts.PropertyAssignment,\n elementExpressions: ts.NodeArray<ts.Expression>\n ) => void\n) {\n visitNgModuleProperty(sourceFile, callback, 'exports');\n}\n\nfunction visitNgModuleProperty(\n sourceFile: ts.SourceFile,\n callback: (\n nodes: ts.PropertyAssignment,\n elementExpressions: ts.NodeArray<ts.Expression>\n ) => void,\n property: string\n) {\n visitNgModules(sourceFile, (_, decoratorExpressionNode) => {\n ts.forEachChild(decoratorExpressionNode, function findTemplates(n) {\n if (\n ts.isPropertyAssignment(n) &&\n ts.isIdentifier(n.name) &&\n n.name.text === property &&\n ts.isArrayLiteralExpression(n.initializer)\n ) {\n callback(n, n.initializer.elements);\n return;\n }\n\n ts.forEachChild(n, findTemplates);\n });\n });\n}\nexport function visitComponents(\n sourceFile: ts.SourceFile,\n callback: (\n classDeclarationNode: ts.ClassDeclaration,\n decoratorExpressionNode: ts.ObjectLiteralExpression\n ) => void\n) {\n visitDecorator(sourceFile, 'Component', callback);\n}\n\nexport function visitNgModules(\n sourceFile: ts.SourceFile,\n callback: (\n classDeclarationNode: ts.ClassDeclaration,\n decoratorExpressionNode: ts.ObjectLiteralExpression\n ) => void\n) {\n visitDecorator(sourceFile, 'NgModule', callback);\n}\n\nexport function visitDecorator(\n sourceFile: ts.SourceFile,\n decoratorName: string,\n callback: (\n classDeclarationNode: ts.ClassDeclaration,\n decoratorExpressionNode: ts.ObjectLiteralExpression\n ) => void\n) {\n ts.forEachChild(sourceFile, function findClassDeclaration(node) {\n if (!ts.isClassDeclaration(node)) {\n ts.forEachChild(node, findClassDeclaration);\n }\n\n const classDeclarationNode = node as ts.ClassDeclaration;\n const decorators = ts.getDecorators(classDeclarationNode);\n\n if (!decorators || !decorators.length) {\n return;\n }\n\n const componentDecorator = decorators.find((d) => {\n return (\n ts.isCallExpression(d.expression) &&\n ts.isIdentifier(d.expression.expression) &&\n d.expression.expression.text === decoratorName\n );\n });\n\n if (!componentDecorator) {\n return;\n }\n\n const { expression } = componentDecorator;\n if (!ts.isCallExpression(expression)) {\n return;\n }\n\n const [arg] = expression.arguments;\n if (!arg || !ts.isObjectLiteralExpression(arg)) {\n return;\n }\n\n callback(classDeclarationNode, arg);\n });\n}\n\nfunction* visit(directory: DirEntry): IterableIterator<ts.SourceFile> {\n for (const path of directory.subfiles) {\n if (path.endsWith('.ts') && !path.endsWith('.d.ts')) {\n const entry = directory.file(path);\n if (entry) {\n const content = entry.content;\n const source = ts.createSourceFile(\n entry.path,\n content.toString().replace(/^\\uFEFF/, ''),\n ts.ScriptTarget.Latest,\n true\n );\n yield source;\n }\n }\n }\n\n for (const path of directory.subdirs) {\n if (path === 'node_modules') {\n continue;\n }\n\n yield* visit(directory.dir(path));\n }\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Signal } from '@angular/core';
|
|
2
|
+
import { IsUnknownRecord } from './ts-helpers';
|
|
3
|
+
export type DeepSignal<T> = Signal<T> & (T extends Record<string, unknown> ? IsUnknownRecord<T> extends true ? unknown : Readonly<{
|
|
4
|
+
[K in keyof T]: T[K] extends Record<string, unknown> ? IsUnknownRecord<T[K]> extends true ? Signal<T[K]> : DeepSignal<T[K]> : Signal<T[K]>;
|
|
5
|
+
}> : unknown);
|
|
6
|
+
export declare function toDeepSignal<T>(signal: Signal<T>): DeepSignal<T>;
|
package/src/helpers.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function excludeKeys<Obj extends Record<string, unknown>, Keys extends string[]>(obj: Obj, keys: Keys): Omit<Obj, Keys[number]>;
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { PartialStateUpdater, patchState } from './patch-state';
|
|
2
|
+
export { signalState } from './signal-state';
|
|
3
|
+
export { signalStore } from './signal-store';
|
|
4
|
+
export { signalStoreFeature, type } from './signal-store-feature';
|
|
5
|
+
export { withComputed } from './with-computed';
|
|
6
|
+
export { withHooks } from './with-hooks';
|
|
7
|
+
export { withMethods } from './with-methods';
|
|
8
|
+
export { withState } from './with-state';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { SignalStateMeta } from './signal-state';
|
|
2
|
+
export type PartialStateUpdater<State extends Record<string, unknown>> = (state: State) => Partial<State>;
|
|
3
|
+
export declare function patchState<State extends Record<string, unknown>>(signalState: SignalStateMeta<State>, ...updaters: Array<Partial<State> | PartialStateUpdater<State>>): void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { WritableSignal } from '@angular/core';
|
|
2
|
+
import { DeepSignal } from './deep-signal';
|
|
3
|
+
import { HasFunctionKeys } from './ts-helpers';
|
|
4
|
+
export declare const STATE_SIGNAL: unique symbol;
|
|
5
|
+
export type SignalStateMeta<State extends Record<string, unknown>> = {
|
|
6
|
+
[STATE_SIGNAL]: WritableSignal<State>;
|
|
7
|
+
};
|
|
8
|
+
type SignalStateCheck<State> = HasFunctionKeys<State> extends false | undefined ? unknown : '@ngrx/signals: signal state cannot contain `Function` property or method names';
|
|
9
|
+
type SignalState<State extends Record<string, unknown>> = DeepSignal<State> & SignalStateMeta<State>;
|
|
10
|
+
export declare function signalState<State extends Record<string, unknown>>(initialState: State & SignalStateCheck<State>): SignalState<State>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { EmptyFeatureResult, MergeFeatureResults, SignalStoreFeature, SignalStoreFeatureResult } from './signal-store-models';
|
|
2
|
+
import { Prettify } from './ts-helpers';
|
|
3
|
+
export declare function signalStoreFeature<F1 extends SignalStoreFeatureResult>(f1: SignalStoreFeature<EmptyFeatureResult, F1>): SignalStoreFeature<EmptyFeatureResult, F1>;
|
|
4
|
+
export declare function signalStoreFeature<F1 extends SignalStoreFeatureResult, F2 extends SignalStoreFeatureResult>(f1: SignalStoreFeature<EmptyFeatureResult, F1>, f2: SignalStoreFeature<{} & F1, F2>): SignalStoreFeature<EmptyFeatureResult, MergeFeatureResults<[F1, F2]>>;
|
|
5
|
+
export declare function signalStoreFeature<F1 extends SignalStoreFeatureResult, F2 extends SignalStoreFeatureResult, F3 extends SignalStoreFeatureResult>(f1: SignalStoreFeature<EmptyFeatureResult, F1>, f2: SignalStoreFeature<{} & F1, F2>, f3: SignalStoreFeature<MergeFeatureResults<[F1, F2]>, F3>): SignalStoreFeature<EmptyFeatureResult, MergeFeatureResults<[F1, F2, F3]>>;
|
|
6
|
+
export declare function signalStoreFeature<F1 extends SignalStoreFeatureResult, F2 extends SignalStoreFeatureResult, F3 extends SignalStoreFeatureResult, F4 extends SignalStoreFeatureResult>(f1: SignalStoreFeature<EmptyFeatureResult, F1>, f2: SignalStoreFeature<{} & F1, F2>, f3: SignalStoreFeature<MergeFeatureResults<[F1, F2]>, F3>, f4: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3]>, F4>): SignalStoreFeature<EmptyFeatureResult, MergeFeatureResults<[F1, F2, F3, F4]>>;
|
|
7
|
+
export declare function signalStoreFeature<F1 extends SignalStoreFeatureResult, F2 extends SignalStoreFeatureResult, F3 extends SignalStoreFeatureResult, F4 extends SignalStoreFeatureResult, F5 extends SignalStoreFeatureResult>(f1: SignalStoreFeature<EmptyFeatureResult, F1>, f2: SignalStoreFeature<{} & F1, F2>, f3: SignalStoreFeature<MergeFeatureResults<[F1, F2]>, F3>, f4: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3]>, F4>, f5: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4]>, F5>): SignalStoreFeature<EmptyFeatureResult, MergeFeatureResults<[F1, F2, F3, F4, F5]>>;
|
|
8
|
+
export declare function signalStoreFeature<F1 extends SignalStoreFeatureResult, F2 extends SignalStoreFeatureResult, F3 extends SignalStoreFeatureResult, F4 extends SignalStoreFeatureResult, F5 extends SignalStoreFeatureResult, F6 extends SignalStoreFeatureResult>(f1: SignalStoreFeature<EmptyFeatureResult, F1>, f2: SignalStoreFeature<{} & F1, F2>, f3: SignalStoreFeature<MergeFeatureResults<[F1, F2]>, F3>, f4: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3]>, F4>, f5: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4]>, F5>, f6: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4, F5]>, F6>): SignalStoreFeature<EmptyFeatureResult, MergeFeatureResults<[F1, F2, F3, F4, F5, F6]>>;
|
|
9
|
+
export declare function signalStoreFeature<Input extends Partial<SignalStoreFeatureResult>, F1 extends SignalStoreFeatureResult>(input: Input, f1: SignalStoreFeature<Prettify<EmptyFeatureResult & Input>, F1>): SignalStoreFeature<Prettify<EmptyFeatureResult & Input>, F1>;
|
|
10
|
+
export declare function signalStoreFeature<Input extends Partial<SignalStoreFeatureResult>, F1 extends SignalStoreFeatureResult, F2 extends SignalStoreFeatureResult>(input: Input, f1: SignalStoreFeature<Prettify<EmptyFeatureResult & Input>, F1>, f2: SignalStoreFeature<MergeFeatureResults<[Prettify<EmptyFeatureResult & Input>, F1]>, F2>): SignalStoreFeature<Prettify<EmptyFeatureResult & Input>, MergeFeatureResults<[F1, F2]>>;
|
|
11
|
+
export declare function signalStoreFeature<Input extends Partial<SignalStoreFeatureResult>, F1 extends SignalStoreFeatureResult, F2 extends SignalStoreFeatureResult, F3 extends SignalStoreFeatureResult>(input: Input, f1: SignalStoreFeature<Prettify<EmptyFeatureResult & Input>, F1>, f2: SignalStoreFeature<MergeFeatureResults<[Prettify<EmptyFeatureResult & Input>, F1]>, F2>, f3: SignalStoreFeature<MergeFeatureResults<[Prettify<EmptyFeatureResult & Input>, F1, F2]>, F3>): SignalStoreFeature<Prettify<EmptyFeatureResult & Input>, MergeFeatureResults<[F1, F2, F3]>>;
|
|
12
|
+
export declare function signalStoreFeature<Input extends Partial<SignalStoreFeatureResult>, F1 extends SignalStoreFeatureResult, F2 extends SignalStoreFeatureResult, F3 extends SignalStoreFeatureResult, F4 extends SignalStoreFeatureResult>(Input: Input, f1: SignalStoreFeature<Prettify<EmptyFeatureResult & Input>, F1>, f2: SignalStoreFeature<MergeFeatureResults<[Prettify<EmptyFeatureResult & Input>, F1]>, F2>, f3: SignalStoreFeature<MergeFeatureResults<[Prettify<EmptyFeatureResult & Input>, F1, F2]>, F3>, f4: SignalStoreFeature<MergeFeatureResults<[Prettify<EmptyFeatureResult & Input>, F1, F2, F3]>, F4>): SignalStoreFeature<Prettify<EmptyFeatureResult & Input>, MergeFeatureResults<[F1, F2, F3, F4]>>;
|
|
13
|
+
export declare function signalStoreFeature<Input extends Partial<SignalStoreFeatureResult>, F1 extends SignalStoreFeatureResult, F2 extends SignalStoreFeatureResult, F3 extends SignalStoreFeatureResult, F4 extends SignalStoreFeatureResult, F5 extends SignalStoreFeatureResult>(input: Input, f1: SignalStoreFeature<Prettify<EmptyFeatureResult & Input>, F1>, f2: SignalStoreFeature<MergeFeatureResults<[Prettify<EmptyFeatureResult & Input>, F1]>, F2>, f3: SignalStoreFeature<MergeFeatureResults<[Prettify<EmptyFeatureResult & Input>, F1, F2]>, F3>, f4: SignalStoreFeature<MergeFeatureResults<[Prettify<EmptyFeatureResult & Input>, F1, F2, F3]>, F4>, f5: SignalStoreFeature<MergeFeatureResults<[Prettify<EmptyFeatureResult & Input>, F1, F2, F3, F4]>, F5>): SignalStoreFeature<Prettify<EmptyFeatureResult & Input>, MergeFeatureResults<[F1, F2, F3, F4, F5]>>;
|
|
14
|
+
export declare function signalStoreFeature<Input extends Partial<SignalStoreFeatureResult>, F1 extends SignalStoreFeatureResult, F2 extends SignalStoreFeatureResult, F3 extends SignalStoreFeatureResult, F4 extends SignalStoreFeatureResult, F5 extends SignalStoreFeatureResult, F6 extends SignalStoreFeatureResult>(input: Input, f1: SignalStoreFeature<Prettify<EmptyFeatureResult & Input>, F1>, f2: SignalStoreFeature<MergeFeatureResults<[Prettify<EmptyFeatureResult & Input>, F1]>, F2>, f3: SignalStoreFeature<MergeFeatureResults<[Prettify<EmptyFeatureResult & Input>, F1, F2]>, F3>, f4: SignalStoreFeature<MergeFeatureResults<[Prettify<EmptyFeatureResult & Input>, F1, F2, F3]>, F4>, f5: SignalStoreFeature<MergeFeatureResults<[Prettify<EmptyFeatureResult & Input>, F1, F2, F3, F4]>, F5>, f6: SignalStoreFeature<MergeFeatureResults<[
|
|
15
|
+
Prettify<EmptyFeatureResult & Input>,
|
|
16
|
+
F1,
|
|
17
|
+
F2,
|
|
18
|
+
F3,
|
|
19
|
+
F4,
|
|
20
|
+
F5
|
|
21
|
+
]>, F6>): SignalStoreFeature<Prettify<EmptyFeatureResult & Input>, MergeFeatureResults<[F1, F2, F3, F4, F5, F6]>>;
|
|
22
|
+
export declare function type<T>(): T;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Signal } from '@angular/core';
|
|
2
|
+
import { DeepSignal } from './deep-signal';
|
|
3
|
+
import { SignalStateMeta } from './signal-state';
|
|
4
|
+
import { IsUnknownRecord, Prettify } from './ts-helpers';
|
|
5
|
+
export type SignalStoreConfig = {
|
|
6
|
+
providedIn: 'root';
|
|
7
|
+
};
|
|
8
|
+
export type SignalStoreSlices<State> = {
|
|
9
|
+
[Key in keyof State]: State[Key] extends Record<string, unknown> ? IsUnknownRecord<State[Key]> extends true ? Signal<State[Key]> : DeepSignal<State[Key]> : Signal<State[Key]>;
|
|
10
|
+
};
|
|
11
|
+
export type SignalStore<FeatureResult extends SignalStoreFeatureResult> = Prettify<SignalStoreSlices<FeatureResult['state']> & FeatureResult['signals'] & FeatureResult['methods'] & SignalStateMeta<Prettify<FeatureResult['state']>>>;
|
|
12
|
+
export type SignalsDictionary = Record<string, Signal<unknown>>;
|
|
13
|
+
export type MethodsDictionary = Record<string, (...args: any[]) => unknown>;
|
|
14
|
+
export type SignalStoreHooks = {
|
|
15
|
+
onInit?: () => void;
|
|
16
|
+
onDestroy?: () => void;
|
|
17
|
+
};
|
|
18
|
+
export type InnerSignalStore<State extends Record<string, unknown> = Record<string, unknown>, Signals extends SignalsDictionary = SignalsDictionary, Methods extends MethodsDictionary = MethodsDictionary> = {
|
|
19
|
+
slices: SignalStoreSlices<State>;
|
|
20
|
+
signals: Signals;
|
|
21
|
+
methods: Methods;
|
|
22
|
+
hooks: SignalStoreHooks;
|
|
23
|
+
} & SignalStateMeta<State>;
|
|
24
|
+
export type SignalStoreFeatureResult = {
|
|
25
|
+
state: Record<string, unknown>;
|
|
26
|
+
signals: SignalsDictionary;
|
|
27
|
+
methods: MethodsDictionary;
|
|
28
|
+
};
|
|
29
|
+
export type EmptyFeatureResult = {
|
|
30
|
+
state: {};
|
|
31
|
+
signals: {};
|
|
32
|
+
methods: {};
|
|
33
|
+
};
|
|
34
|
+
export type SignalStoreFeature<Input extends SignalStoreFeatureResult = SignalStoreFeatureResult, Output extends SignalStoreFeatureResult = SignalStoreFeatureResult> = (store: InnerSignalStore<Input['state'], Input['signals'], Input['methods']>) => InnerSignalStore<Output['state'], Output['signals'], Output['methods']>;
|
|
35
|
+
export type MergeFeatureResults<FeatureResults extends SignalStoreFeatureResult[]> = FeatureResults extends [] ? {} : FeatureResults extends [infer First extends SignalStoreFeatureResult] ? First : FeatureResults extends [
|
|
36
|
+
infer First extends SignalStoreFeatureResult,
|
|
37
|
+
infer Second extends SignalStoreFeatureResult
|
|
38
|
+
] ? MergeTwoFeatureResults<First, Second> : FeatureResults extends [
|
|
39
|
+
infer First extends SignalStoreFeatureResult,
|
|
40
|
+
infer Second extends SignalStoreFeatureResult,
|
|
41
|
+
...infer Rest extends SignalStoreFeatureResult[]
|
|
42
|
+
] ? MergeFeatureResults<[MergeTwoFeatureResults<First, Second>, ...Rest]> : never;
|
|
43
|
+
type FeatureResultKeys<FeatureResult extends SignalStoreFeatureResult> = keyof FeatureResult['state'] | keyof FeatureResult['signals'] | keyof FeatureResult['methods'];
|
|
44
|
+
type MergeTwoFeatureResults<First extends SignalStoreFeatureResult, Second extends SignalStoreFeatureResult> = {
|
|
45
|
+
state: Omit<First['state'], FeatureResultKeys<Second>>;
|
|
46
|
+
signals: Omit<First['signals'], FeatureResultKeys<Second>>;
|
|
47
|
+
methods: Omit<First['methods'], FeatureResultKeys<Second>>;
|
|
48
|
+
} & Second;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Type } from '@angular/core';
|
|
2
|
+
import { EmptyFeatureResult, InnerSignalStore, MergeFeatureResults, SignalStore, SignalStoreConfig, SignalStoreFeature, SignalStoreFeatureResult } from './signal-store-models';
|
|
3
|
+
export declare function signalStore<F1 extends SignalStoreFeatureResult>(f1: SignalStoreFeature<EmptyFeatureResult, F1>): Type<SignalStore<F1>>;
|
|
4
|
+
export declare function signalStore<F1 extends SignalStoreFeatureResult, F2 extends SignalStoreFeatureResult>(f1: SignalStoreFeature<EmptyFeatureResult, F1>, f2: SignalStoreFeature<{} & F1, F2>): Type<SignalStore<MergeFeatureResults<[F1, F2]>>>;
|
|
5
|
+
export declare function signalStore<F1 extends SignalStoreFeatureResult, F2 extends SignalStoreFeatureResult, F3 extends SignalStoreFeatureResult>(f1: SignalStoreFeature<EmptyFeatureResult, F1>, f2: SignalStoreFeature<{} & F1, F2>, f3: SignalStoreFeature<MergeFeatureResults<[F1, F2]>, F3>): Type<SignalStore<MergeFeatureResults<[F1, F2, F3]>>>;
|
|
6
|
+
export declare function signalStore<F1 extends SignalStoreFeatureResult, F2 extends SignalStoreFeatureResult, F3 extends SignalStoreFeatureResult, F4 extends SignalStoreFeatureResult>(f1: SignalStoreFeature<EmptyFeatureResult, F1>, f2: SignalStoreFeature<{} & F1, F2>, f3: SignalStoreFeature<MergeFeatureResults<[F1, F2]>, F3>, f4: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3]>, F4>): Type<SignalStore<MergeFeatureResults<[F1, F2, F3, F4]>>>;
|
|
7
|
+
export declare function signalStore<F1 extends SignalStoreFeatureResult, F2 extends SignalStoreFeatureResult, F3 extends SignalStoreFeatureResult, F4 extends SignalStoreFeatureResult, F5 extends SignalStoreFeatureResult>(f1: SignalStoreFeature<EmptyFeatureResult, F1>, f2: SignalStoreFeature<{} & F1, F2>, f3: SignalStoreFeature<MergeFeatureResults<[F1, F2]>, F3>, f4: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3]>, F4>, f5: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4]>, F5>): Type<SignalStore<MergeFeatureResults<[F1, F2, F3, F4, F5]>>>;
|
|
8
|
+
export declare function signalStore<F1 extends SignalStoreFeatureResult, F2 extends SignalStoreFeatureResult, F3 extends SignalStoreFeatureResult, F4 extends SignalStoreFeatureResult, F5 extends SignalStoreFeatureResult, F6 extends SignalStoreFeatureResult>(f1: SignalStoreFeature<EmptyFeatureResult, F1>, f2: SignalStoreFeature<{} & F1, F2>, f3: SignalStoreFeature<MergeFeatureResults<[F1, F2]>, F3>, f4: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3]>, F4>, f5: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4]>, F5>, f6: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4, F5]>, F6>): Type<SignalStore<MergeFeatureResults<[F1, F2, F3, F4, F5, F6]>>>;
|
|
9
|
+
export declare function signalStore<F1 extends SignalStoreFeatureResult, F2 extends SignalStoreFeatureResult, F3 extends SignalStoreFeatureResult, F4 extends SignalStoreFeatureResult, F5 extends SignalStoreFeatureResult, F6 extends SignalStoreFeatureResult, F7 extends SignalStoreFeatureResult>(f1: SignalStoreFeature<EmptyFeatureResult, F1>, f2: SignalStoreFeature<{} & F1, F2>, f3: SignalStoreFeature<MergeFeatureResults<[F1, F2]>, F3>, f4: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3]>, F4>, f5: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4]>, F5>, f6: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4, F5]>, F6>, f7: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4, F5, F6]>, F7>): Type<SignalStore<MergeFeatureResults<[F1, F2, F3, F4, F5, F6, F7]>>>;
|
|
10
|
+
export declare function signalStore<F1 extends SignalStoreFeatureResult, F2 extends SignalStoreFeatureResult, F3 extends SignalStoreFeatureResult, F4 extends SignalStoreFeatureResult, F5 extends SignalStoreFeatureResult, F6 extends SignalStoreFeatureResult, F7 extends SignalStoreFeatureResult, F8 extends SignalStoreFeatureResult>(f1: SignalStoreFeature<EmptyFeatureResult, F1>, f2: SignalStoreFeature<{} & F1, F2>, f3: SignalStoreFeature<MergeFeatureResults<[F1, F2]>, F3>, f4: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3]>, F4>, f5: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4]>, F5>, f6: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4, F5]>, F6>, f7: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4, F5, F6]>, F7>, f8: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4, F5, F6, F7]>, F8>): Type<SignalStore<MergeFeatureResults<[F1, F2, F3, F4, F5, F6, F7, F8]>>>;
|
|
11
|
+
export declare function signalStore<F1 extends SignalStoreFeatureResult, F2 extends SignalStoreFeatureResult, F3 extends SignalStoreFeatureResult, F4 extends SignalStoreFeatureResult, F5 extends SignalStoreFeatureResult, F6 extends SignalStoreFeatureResult, F7 extends SignalStoreFeatureResult, F8 extends SignalStoreFeatureResult, F9 extends SignalStoreFeatureResult>(f1: SignalStoreFeature<EmptyFeatureResult, F1>, f2: SignalStoreFeature<{} & F1, F2>, f3: SignalStoreFeature<MergeFeatureResults<[F1, F2]>, F3>, f4: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3]>, F4>, f5: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4]>, F5>, f6: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4, F5]>, F6>, f7: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4, F5, F6]>, F7>, f8: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4, F5, F6, F7]>, F8>, f9: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4, F5, F6, F7, F8]>, F9>): Type<SignalStore<MergeFeatureResults<[F1, F2, F3, F4, F5, F6, F7, F8, F9]>>>;
|
|
12
|
+
export declare function signalStore<F1 extends SignalStoreFeatureResult>(config: SignalStoreConfig, f1: SignalStoreFeature<EmptyFeatureResult, F1>): Type<SignalStore<F1>>;
|
|
13
|
+
export declare function signalStore<F1 extends SignalStoreFeatureResult, F2 extends SignalStoreFeatureResult>(config: SignalStoreConfig, f1: SignalStoreFeature<EmptyFeatureResult, F1>, f2: SignalStoreFeature<{} & F1, F2>): Type<SignalStore<MergeFeatureResults<[F1, F2]>>>;
|
|
14
|
+
export declare function signalStore<F1 extends SignalStoreFeatureResult, F2 extends SignalStoreFeatureResult, F3 extends SignalStoreFeatureResult>(config: SignalStoreConfig, f1: SignalStoreFeature<EmptyFeatureResult, F1>, f2: SignalStoreFeature<{} & F1, F2>, f3: SignalStoreFeature<MergeFeatureResults<[F1, F2]>, F3>): Type<SignalStore<MergeFeatureResults<[F1, F2, F3]>>>;
|
|
15
|
+
export declare function signalStore<F1 extends SignalStoreFeatureResult, F2 extends SignalStoreFeatureResult, F3 extends SignalStoreFeatureResult, F4 extends SignalStoreFeatureResult>(config: SignalStoreConfig, f1: SignalStoreFeature<EmptyFeatureResult, F1>, f2: SignalStoreFeature<{} & F1, F2>, f3: SignalStoreFeature<MergeFeatureResults<[F1, F2]>, F3>, f4: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3]>, F4>): Type<SignalStore<MergeFeatureResults<[F1, F2, F3, F4]>>>;
|
|
16
|
+
export declare function signalStore<F1 extends SignalStoreFeatureResult, F2 extends SignalStoreFeatureResult, F3 extends SignalStoreFeatureResult, F4 extends SignalStoreFeatureResult, F5 extends SignalStoreFeatureResult>(config: SignalStoreConfig, f1: SignalStoreFeature<EmptyFeatureResult, F1>, f2: SignalStoreFeature<{} & F1, F2>, f3: SignalStoreFeature<MergeFeatureResults<[F1, F2]>, F3>, f4: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3]>, F4>, f5: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4]>, F5>): Type<SignalStore<MergeFeatureResults<[F1, F2, F3, F4, F5]>>>;
|
|
17
|
+
export declare function signalStore<F1 extends SignalStoreFeatureResult, F2 extends SignalStoreFeatureResult, F3 extends SignalStoreFeatureResult, F4 extends SignalStoreFeatureResult, F5 extends SignalStoreFeatureResult, F6 extends SignalStoreFeatureResult>(config: SignalStoreConfig, f1: SignalStoreFeature<EmptyFeatureResult, F1>, f2: SignalStoreFeature<{} & F1, F2>, f3: SignalStoreFeature<MergeFeatureResults<[F1, F2]>, F3>, f4: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3]>, F4>, f5: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4]>, F5>, f6: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4, F5]>, F6>): Type<SignalStore<MergeFeatureResults<[F1, F2, F3, F4, F5, F6]>>>;
|
|
18
|
+
export declare function signalStore<F1 extends SignalStoreFeatureResult, F2 extends SignalStoreFeatureResult, F3 extends SignalStoreFeatureResult, F4 extends SignalStoreFeatureResult, F5 extends SignalStoreFeatureResult, F6 extends SignalStoreFeatureResult, F7 extends SignalStoreFeatureResult>(config: SignalStoreConfig, f1: SignalStoreFeature<EmptyFeatureResult, F1>, f2: SignalStoreFeature<{} & F1, F2>, f3: SignalStoreFeature<MergeFeatureResults<[F1, F2]>, F3>, f4: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3]>, F4>, f5: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4]>, F5>, f6: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4, F5]>, F6>, f7: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4, F5, F6]>, F7>): Type<SignalStore<MergeFeatureResults<[F1, F2, F3, F4, F5, F6, F7]>>>;
|
|
19
|
+
export declare function signalStore<F1 extends SignalStoreFeatureResult, F2 extends SignalStoreFeatureResult, F3 extends SignalStoreFeatureResult, F4 extends SignalStoreFeatureResult, F5 extends SignalStoreFeatureResult, F6 extends SignalStoreFeatureResult, F7 extends SignalStoreFeatureResult, F8 extends SignalStoreFeatureResult>(config: SignalStoreConfig, f1: SignalStoreFeature<EmptyFeatureResult, F1>, f2: SignalStoreFeature<{} & F1, F2>, f3: SignalStoreFeature<MergeFeatureResults<[F1, F2]>, F3>, f4: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3]>, F4>, f5: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4]>, F5>, f6: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4, F5]>, F6>, f7: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4, F5, F6]>, F7>, f8: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4, F5, F6, F7]>, F8>): Type<SignalStore<MergeFeatureResults<[F1, F2, F3, F4, F5, F6, F7, F8]>>>;
|
|
20
|
+
export declare function signalStore<F1 extends SignalStoreFeatureResult, F2 extends SignalStoreFeatureResult, F3 extends SignalStoreFeatureResult, F4 extends SignalStoreFeatureResult, F5 extends SignalStoreFeatureResult, F6 extends SignalStoreFeatureResult, F7 extends SignalStoreFeatureResult, F8 extends SignalStoreFeatureResult, F9 extends SignalStoreFeatureResult>(config: SignalStoreConfig, f1: SignalStoreFeature<EmptyFeatureResult, F1>, f2: SignalStoreFeature<{} & F1, F2>, f3: SignalStoreFeature<MergeFeatureResults<[F1, F2]>, F3>, f4: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3]>, F4>, f5: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4]>, F5>, f6: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4, F5]>, F6>, f7: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4, F5, F6]>, F7>, f8: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4, F5, F6, F7]>, F8>, f9: SignalStoreFeature<MergeFeatureResults<[F1, F2, F3, F4, F5, F6, F7, F8]>, F9>): Type<SignalStore<MergeFeatureResults<[F1, F2, F3, F4, F5, F6, F7, F8, F9]>>>;
|
|
21
|
+
export declare function getInitialInnerStore(): InnerSignalStore;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type Prettify<T> = {
|
|
2
|
+
[K in keyof T]: T[K];
|
|
3
|
+
} & {};
|
|
4
|
+
export type IsUnknownRecord<T> = string extends keyof T ? true : number extends keyof T ? true : false;
|
|
5
|
+
export type HasOptionalProps<T> = T extends Required<T> ? false : true;
|
|
6
|
+
export type HasFunctionKeys<T> = T extends Record<string, unknown> ? {
|
|
7
|
+
[K in keyof T]: K extends keyof Function ? true : HasFunctionKeys<T[K]>;
|
|
8
|
+
}[keyof T] : false;
|
|
9
|
+
export type HasNestedFunctionKeys<T> = {
|
|
10
|
+
[K in keyof T]: HasFunctionKeys<T[K]>;
|
|
11
|
+
}[keyof T];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { EmptyFeatureResult, SignalsDictionary, SignalStoreFeature, SignalStoreFeatureResult, SignalStoreSlices } from './signal-store-models';
|
|
2
|
+
import { Prettify } from './ts-helpers';
|
|
3
|
+
export declare function withComputed<Input extends SignalStoreFeatureResult, Signals extends SignalsDictionary>(signalsFactory: (store: Prettify<SignalStoreSlices<Input['state']> & Input['signals']>) => Signals): SignalStoreFeature<Input, EmptyFeatureResult & {
|
|
4
|
+
signals: Signals;
|
|
5
|
+
}>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SignalStateMeta } from './signal-state';
|
|
2
|
+
import { EmptyFeatureResult, SignalStoreFeature, SignalStoreSlices, SignalStoreFeatureResult } from './signal-store-models';
|
|
3
|
+
import { Prettify } from './ts-helpers';
|
|
4
|
+
type HooksFactory<Input extends SignalStoreFeatureResult> = (store: Prettify<SignalStoreSlices<Input['state']> & Input['signals'] & Input['methods'] & SignalStateMeta<Prettify<Input['state']>>>) => void;
|
|
5
|
+
export declare function withHooks<Input extends SignalStoreFeatureResult>(hooks: {
|
|
6
|
+
onInit?: HooksFactory<Input>;
|
|
7
|
+
onDestroy?: HooksFactory<Input>;
|
|
8
|
+
}): SignalStoreFeature<Input, EmptyFeatureResult>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { SignalStateMeta } from './signal-state';
|
|
2
|
+
import { EmptyFeatureResult, MethodsDictionary, SignalStoreFeature, SignalStoreFeatureResult, SignalStoreSlices } from './signal-store-models';
|
|
3
|
+
import { Prettify } from './ts-helpers';
|
|
4
|
+
export declare function withMethods<Input extends SignalStoreFeatureResult, Methods extends MethodsDictionary>(methodsFactory: (store: Prettify<SignalStoreSlices<Input['state']> & Input['signals'] & Input['methods'] & SignalStateMeta<Prettify<Input['state']>>>) => Methods): SignalStoreFeature<Input, EmptyFeatureResult & {
|
|
5
|
+
methods: Methods;
|
|
6
|
+
}>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EmptyFeatureResult, SignalStoreFeature } from './signal-store-models';
|
|
2
|
+
import { HasNestedFunctionKeys, HasOptionalProps, IsUnknownRecord } from './ts-helpers';
|
|
3
|
+
type WithStateCheck<State> = IsUnknownRecord<State> extends true ? '@ngrx/signals: root state keys must be string literals' : HasOptionalProps<State> extends true ? '@ngrx/signals: root state slices cannot be optional' : HasNestedFunctionKeys<State> extends false | undefined ? unknown : '@ngrx/signals: nested state slices cannot contain `Function` property or method names';
|
|
4
|
+
export declare function withState<State extends Record<string, unknown>>(state: State & WithStateCheck<State>): SignalStoreFeature<EmptyFeatureResult, EmptyFeatureResult & {
|
|
5
|
+
state: State;
|
|
6
|
+
}>;
|
|
7
|
+
export declare function withState<State extends Record<string, unknown>>(stateFactory: () => State & WithStateCheck<State>): SignalStoreFeature<EmptyFeatureResult, EmptyFeatureResult & {
|
|
8
|
+
state: State;
|
|
9
|
+
}>;
|
|
10
|
+
export {};
|