@tstdl/base 0.88.0-alpha1 → 0.88.0-alpha2

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.
Files changed (76) hide show
  1. package/authentication/index.d.ts +1 -0
  2. package/authentication/index.js +1 -0
  3. package/browser/index.d.ts +1 -0
  4. package/browser/index.js +1 -0
  5. package/data-structures/index.d.ts +1 -0
  6. package/data-structures/index.js +1 -0
  7. package/http/client/adapters/index.d.ts +1 -0
  8. package/http/client/adapters/index.js +1 -0
  9. package/http/client/index.d.ts +2 -0
  10. package/http/client/index.js +2 -0
  11. package/mail/clients/index.d.ts +1 -0
  12. package/mail/clients/index.js +1 -0
  13. package/mail/index.d.ts +2 -0
  14. package/mail/index.js +2 -0
  15. package/mail/mail.service.d.ts +1 -1
  16. package/mail/mail.service.js +1 -1
  17. package/mail/module.d.ts +1 -1
  18. package/mail/module.js +1 -1
  19. package/mail/repositories/index.d.ts +1 -0
  20. package/mail/repositories/index.js +1 -0
  21. package/mail/repositories/mail-log.repository.d.ts +4 -0
  22. package/mail/{mail-log.repository.js → repositories/mail-log.repository.js} +1 -1
  23. package/mail/repositories/mongo/index.d.ts +1 -0
  24. package/mail/repositories/mongo/index.js +1 -0
  25. package/mail/repositories/{mongo-mail-log.repository.d.ts → mongo/mongo-mail-log.repository.d.ts} +6 -6
  26. package/mail/repositories/{mongo-mail-log.repository.js → mongo/mongo-mail-log.repository.js} +3 -3
  27. package/package.json +90 -2
  28. package/random/number-generator/index.d.ts +2 -0
  29. package/random/number-generator/index.js +2 -0
  30. package/random/number-generator/utils.d.ts +1 -0
  31. package/random/number-generator/utils.js +5 -0
  32. package/rpc/endpoints/index.d.ts +1 -0
  33. package/rpc/endpoints/index.js +1 -0
  34. package/rpc/endpoints/message-port.rpc-endpoint.js +1 -1
  35. package/signals/implementation/api.d.ts +1 -18
  36. package/signals/implementation/api.js +1 -10
  37. package/signals/implementation/computed.js +42 -94
  38. package/signals/implementation/effect.d.ts +1 -1
  39. package/signals/implementation/effect.js +16 -15
  40. package/signals/implementation/graph.d.ts +118 -73
  41. package/signals/implementation/graph.js +235 -156
  42. package/signals/implementation/signal.js +58 -81
  43. package/signals/implementation/watch.d.ts +2 -18
  44. package/signals/implementation/watch.js +37 -54
  45. package/sse/index.d.ts +1 -0
  46. package/sse/index.js +1 -0
  47. package/templates/providers/index.d.ts +2 -0
  48. package/templates/providers/index.js +2 -0
  49. package/templates/renderers/index.d.ts +4 -0
  50. package/templates/renderers/index.js +4 -0
  51. package/templates/resolvers/index.d.ts +3 -0
  52. package/templates/resolvers/index.js +3 -0
  53. package/templates/types/index.d.ts +1 -0
  54. package/templates/types/index.js +1 -0
  55. package/text/dynamic-text.model.js +3 -5
  56. package/theme/adapters/index.d.ts +2 -0
  57. package/theme/adapters/index.js +2 -0
  58. package/async-iterator-symbol.d.ts +0 -1
  59. package/async-iterator-symbol.js +0 -6
  60. package/mail/mail-log.repository.d.ts +0 -4
  61. package/notification/api.d.ts +0 -15
  62. package/notification/api.js +0 -28
  63. package/notification/models/index.d.ts +0 -2
  64. package/notification/models/index.js +0 -2
  65. package/notification/models/notification-channel-job.model.d.ts +0 -3
  66. package/notification/models/notification-channel-job.model.js +0 -1
  67. package/notification/models/notification.model.d.ts +0 -45
  68. package/notification/models/notification.model.js +0 -103
  69. package/notification/module.d.ts +0 -9
  70. package/notification/module.js +0 -10
  71. package/notification/notification-channel.service.d.ts +0 -5
  72. package/notification/notification-channel.service.js +0 -2
  73. package/notification/notification.repository.d.ts +0 -5
  74. package/notification/notification.repository.js +0 -2
  75. package/notification/notification.service.d.ts +0 -8
  76. package/notification/notification.service.js +0 -36
@@ -1,2 +1,3 @@
1
1
  export * from './authentication.api.js';
2
+ export * from './errors/index.js';
2
3
  export * from './models/index.js';
@@ -1,2 +1,3 @@
1
1
  export * from './authentication.api.js';
2
+ export * from './errors/index.js';
2
3
  export * from './models/index.js';
@@ -7,4 +7,5 @@ export * from './frame-controller.js';
7
7
  export * from './locator-controller.js';
8
8
  export * from './module.js';
9
9
  export * from './page-controller.js';
10
+ export * from './pdf-options.js';
10
11
  export * from './types.js';
package/browser/index.js CHANGED
@@ -7,4 +7,5 @@ export * from './frame-controller.js';
7
7
  export * from './locator-controller.js';
8
8
  export * from './module.js';
9
9
  export * from './page-controller.js';
10
+ export * from './pdf-options.js';
10
11
  export * from './types.js';
@@ -4,6 +4,7 @@ export * from './cache.js';
4
4
  export * from './circular-buffer.js';
5
5
  export * from './collection.js';
6
6
  export * from './dictionary.js';
7
+ export * from './distinct-collection.js';
7
8
  export * from './index-out-of-bounds.error.js';
8
9
  export * from './iterable-weak-map.js';
9
10
  export * from './linked-list.js';
@@ -4,6 +4,7 @@ export * from './cache.js';
4
4
  export * from './circular-buffer.js';
5
5
  export * from './collection.js';
6
6
  export * from './dictionary.js';
7
+ export * from './distinct-collection.js';
7
8
  export * from './index-out-of-bounds.error.js';
8
9
  export * from './iterable-weak-map.js';
9
10
  export * from './linked-list.js';
@@ -0,0 +1 @@
1
+ export * from './undici-http-client.adapter.js';
@@ -0,0 +1 @@
1
+ export * from './undici-http-client.adapter.js';
@@ -3,4 +3,6 @@ export * from './http-client-request.js';
3
3
  export * from './http-client-response.js';
4
4
  export * from './http-client.adapter.js';
5
5
  export * from './http-client.js';
6
+ export * from './middleware.js';
6
7
  export * from './module.js';
8
+ export * from './tokens.js';
@@ -3,4 +3,6 @@ export * from './http-client-request.js';
3
3
  export * from './http-client-response.js';
4
4
  export * from './http-client.adapter.js';
5
5
  export * from './http-client.js';
6
+ export * from './middleware.js';
6
7
  export * from './module.js';
8
+ export * from './tokens.js';
@@ -0,0 +1 @@
1
+ export * from './nodemailer.mail-client.js';
@@ -0,0 +1 @@
1
+ export * from './nodemailer.mail-client.js';
package/mail/index.d.ts CHANGED
@@ -2,4 +2,6 @@ export * from './mail.client.js';
2
2
  export * from './mail.service.js';
3
3
  export * from './models/index.js';
4
4
  export * from './module.js';
5
+ export * from './repositories/index.js';
6
+ export * from './repositories/mail-log.repository.js';
5
7
  export * from './tokens.js';
package/mail/index.js CHANGED
@@ -2,4 +2,6 @@ export * from './mail.client.js';
2
2
  export * from './mail.service.js';
3
3
  export * from './models/index.js';
4
4
  export * from './module.js';
5
+ export * from './repositories/index.js';
6
+ export * from './repositories/mail-log.repository.js';
5
7
  export * from './tokens.js';
@@ -1,7 +1,7 @@
1
1
  import { Logger } from '../logger/index.js';
2
2
  import { TemplateService } from '../templates/template.service.js';
3
3
  import type { TypedOmit } from '../types.js';
4
- import { MailLogRepository } from './mail-log.repository.js';
4
+ import { MailLogRepository } from './repositories/mail-log.repository.js';
5
5
  import { MailClient } from './mail.client.js';
6
6
  import type { DefaultMailData, MailData, MailSendResult, MailTemplate } from './models/index.js';
7
7
  export declare class MailService {
@@ -16,7 +16,7 @@ import { TemplateService } from '../templates/template.service.js';
16
16
  import { currentTimestamp } from '../utils/date-time.js';
17
17
  import { formatError } from '../utils/format-error.js';
18
18
  import { isDefined } from '../utils/type-guards.js';
19
- import { MailLogRepository } from './mail-log.repository.js';
19
+ import { MailLogRepository } from './repositories/mail-log.repository.js';
20
20
  import { MailClient } from './mail.client.js';
21
21
  import { MAIL_DEFAULT_DATA } from './tokens.js';
22
22
  let MailService = class MailService {
package/mail/module.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Type } from '../types.js';
2
- import { MailLogRepository } from './mail-log.repository.js';
2
+ import { MailLogRepository } from './repositories/mail-log.repository.js';
3
3
  import { MailClient, MailClientConfig } from './mail.client.js';
4
4
  import type { DefaultMailData } from './models/index.js';
5
5
  export type MailModuleConfig = {
package/mail/module.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Injector } from '../injector/injector.js';
2
2
  import { isDefined } from '../utils/type-guards.js';
3
- import { MailLogRepository } from './mail-log.repository.js';
3
+ import { MailLogRepository } from './repositories/mail-log.repository.js';
4
4
  import { MailClient, MailClientConfig } from './mail.client.js';
5
5
  import { MAIL_DEFAULT_DATA } from './tokens.js';
6
6
  /**
@@ -0,0 +1 @@
1
+ export * from './mongo/mongo-mail-log.repository.js';
@@ -0,0 +1 @@
1
+ export * from './mongo/mongo-mail-log.repository.js';
@@ -0,0 +1,4 @@
1
+ import { EntityRepository } from '../../database/index.js';
2
+ import type { MailLog } from '../models/mail-log.model.js';
3
+ export declare abstract class MailLogRepository extends EntityRepository<MailLog> {
4
+ }
@@ -1,3 +1,3 @@
1
- import { EntityRepository } from '../database/index.js';
1
+ import { EntityRepository } from '../../database/index.js';
2
2
  export class MailLogRepository extends EntityRepository {
3
3
  }
@@ -0,0 +1 @@
1
+ export * from './mongo-mail-log.repository.js';
@@ -0,0 +1 @@
1
+ export * from './mongo-mail-log.repository.js';
@@ -1,9 +1,9 @@
1
- import type { CollectionArgument } from '../../database/mongo/index.js';
2
- import { Collection, MongoEntityRepository } from '../../database/mongo/index.js';
3
- import { resolveArgumentType } from '../../injector/index.js';
4
- import type { Resolvable } from '../../injector/interfaces.js';
5
- import { Logger } from '../../logger/index.js';
6
- import type { MailLog } from '../models/mail-log.model.js';
1
+ import type { CollectionArgument } from '../../../database/mongo/index.js';
2
+ import { Collection, MongoEntityRepository } from '../../../database/mongo/index.js';
3
+ import { resolveArgumentType } from '../../../injector/index.js';
4
+ import type { Resolvable } from '../../../injector/interfaces.js';
5
+ import { Logger } from '../../../logger/index.js';
6
+ import type { MailLog } from '../../models/mail-log.model.js';
7
7
  export type MongoMailLogRepositoryConfig = {
8
8
  config?: MongoMailLogRepositoryArgument;
9
9
  };
@@ -10,9 +10,9 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  var __param = (this && this.__param) || function (paramIndex, decorator) {
11
11
  return function (target, key) { decorator(target, key, paramIndex); }
12
12
  };
13
- import { Collection, MongoEntityRepository, noopTransformer } from '../../database/mongo/index.js';
14
- import { ForwardArg, Singleton, resolveArgumentType } from '../../injector/index.js';
15
- import { Logger } from '../../logger/index.js';
13
+ import { Collection, MongoEntityRepository, noopTransformer } from '../../../database/mongo/index.js';
14
+ import { ForwardArg, Singleton, resolveArgumentType } from '../../../injector/index.js';
15
+ import { Logger } from '../../../logger/index.js';
16
16
  export const mongoMailLogRepositoryConfig = {};
17
17
  const indexes = [];
18
18
  let MongoMailLogRepository = class MongoMailLogRepository extends MongoEntityRepository {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.88.0-alpha1",
3
+ "version": "0.88.0-alpha2",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -19,7 +19,95 @@
19
19
  "tsc-alias:watch": "tsc-alias --watch"
20
20
  },
21
21
  "exports": {
22
- "./schema": "./schema/index.js"
22
+ "./tsconfig.json": "./tsconfig.json",
23
+
24
+ "./": "./index.js",
25
+ "./environment": "./environment.js",
26
+ "./interfaces": "./interfaces.js",
27
+ "./polyfills": "./polyfills.js",
28
+ "./process-shutdown": "./process-shutdown.js",
29
+ "./supports": "./supports.js",
30
+ "./tokens": "./tokens.js",
31
+ "./types": "./types.js",
32
+ "./web-types": "./web-types.js",
33
+
34
+ "./api": "./api/index.js",
35
+ "./api/client": "./api/client/index.js",
36
+ "./api/server": "./api/server/index.js",
37
+ "./application": "./application/index.js",
38
+ "./authentication": "./authentication/index.js",
39
+ "./authentication/client": "./authentication/client/index.js",
40
+ "./authentication/server": "./authentication/server/index.js",
41
+ "./browser": "./browser/index.js",
42
+ "./cancellation": "./cancellation/index.js",
43
+ "./cookie": "./cookie/index.js",
44
+ "./data-structures": "./data-structures/index.js",
45
+ "./database": "./database/index.js",
46
+ "./database/mongo": "./database/mongo/index.js",
47
+ "./decorators": "./decorators/index.js",
48
+ "./disposable": "./disposable/index.js",
49
+ "./distributed-loop": "./distributed-loop/index.js",
50
+ "./enumerable": "./enumerable/index.js",
51
+ "./error": "./error/index.js",
52
+ "./function": "./function/index.js",
53
+ "./http": "./http/index.js",
54
+ "./http/client/adapters": "./http/client/adapters/index.js",
55
+ "./http/server": "./http/server/index.js",
56
+ "./http/server/node": "./http/server/node/index.js",
57
+ "./image-service": "./image-service/index.js",
58
+ "./image-service/imgproxy": "./image-service/imgproxy/index.js",
59
+ "./injector": "./injector/index.js",
60
+ "./json-path": "./json-path/index.js",
61
+ "./key-value-store": "./key-value-store/index.js",
62
+ "./key-value-store/mongo": "./key-value-store/mongo/index.js",
63
+ "./lock": "./lock/index.js",
64
+ "./lock/mongo": "./lock/mongo/index.js",
65
+ "./lock/web": "./lock/web/index.js",
66
+ "./logger": "./logger/index.js",
67
+ "./logger/console": "./logger/console/index.js",
68
+ "./logger/noop": "./logger/noop/index.js",
69
+ "./mail": "./mail/index.js",
70
+ "./mail/clients": "./mail/clients/index.js",
71
+ "./mail/repositories/mongo": "./mail/repositories/mongo/index.js",
72
+ "./memory": "./memory/index.js",
73
+ "./message-bus": "./message-bus/index.js",
74
+ "./message-bus/broadcast-channel": "./message-bus/broadcast-channel/index.js",
75
+ "./message-bus/local": "./message-bus/local/index.js",
76
+ "./migration": "./migration/index.js",
77
+ "./migration/mongo": "./migration/mongo/index.js",
78
+ "./module": "./module/index.js",
79
+ "./module/modules": "./module/modules/index.js",
80
+ "./object-storage/s3": "./object-storage/s3/index.js",
81
+ "./openid-connect": "./openid-connect/index.js",
82
+ "./password": "./password/index.js",
83
+ "./pdf": "./pdf/index.js",
84
+ "./pool": "./pool/index.js",
85
+ "./promise": "./promise/index.js",
86
+ "./queue": "./queue/index.js",
87
+ "./queue/mongo": "./queue/mongo/index.js",
88
+ "./reflection": "./reflection/index.js",
89
+ "./rpc": "./rpc/index.js",
90
+ "./rpc/endpoints": "./rpc/endpoints/index.js",
91
+ "./rxjs": "./rxjs/index.js",
92
+ "./schema": "./schema/index.js",
93
+ "./search-index": "./search-index/index.js",
94
+ "./search-index/elastic": "./search-index/elastic/index.js",
95
+ "./search-index/memory": "./search-index/memory/index.js",
96
+ "./serializer": "./serializer/index.js",
97
+ "./serializer/handlers": "./serializer/handlers/index.js",
98
+ "./signals": "./signals/index.js",
99
+ "./signals/implementation": "./signals/implementation/index.js",
100
+ "./sse": "./sse/index.js",
101
+ "./templates": "./templates/index.js",
102
+ "./templates/providers": "./templates/providers/index.js",
103
+ "./templates/renderers": "./templates/renderers/index.js",
104
+ "./templates/resolvers": "./templates/resolvers/index.js",
105
+ "./templates/types": "./templates/types/index.js",
106
+ "./text": "./text/index.js",
107
+ "./theme": "./theme/index.js",
108
+ "./theme/adapters": "./theme/adapters/index.js",
109
+ "./threading": "./threading/index.js",
110
+ "./types/geo-json": "./types/geo-json.js"
23
111
  },
24
112
  "dependencies": {
25
113
  "disposablestack": "^1.1.1",
@@ -1,3 +1,5 @@
1
1
  export * from './mulberry32.js';
2
+ export * from './random-number-generator-function.js';
3
+ export * from './random-number-generator.js';
2
4
  export * from './seeded-random-number-generator.js';
3
5
  export * from './sfc32.js';
@@ -1,3 +1,5 @@
1
1
  export * from './mulberry32.js';
2
+ export * from './random-number-generator-function.js';
3
+ export * from './random-number-generator.js';
2
4
  export * from './seeded-random-number-generator.js';
3
5
  export * from './sfc32.js';
@@ -1 +1,2 @@
1
1
  export declare function random32BitSeed(): number;
2
+ export declare function random32BitSeedCrypto(): number;
@@ -1,3 +1,8 @@
1
+ import { getRandomBytes } from '../../utils/random.js';
1
2
  export function random32BitSeed() {
2
3
  return Math.floor(Math.random() * (2 ** 32));
3
4
  }
5
+ export function random32BitSeedCrypto() {
6
+ const bytes = getRandomBytes(4);
7
+ return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getUint32(0);
8
+ }
@@ -0,0 +1 @@
1
+ export * from './message-port.rpc-endpoint.js';
@@ -0,0 +1 @@
1
+ export * from './message-port.rpc-endpoint.js';
@@ -1,5 +1,5 @@
1
- import { isBrowser } from '../../environment.js';
2
1
  import { fromEvent, map } from 'rxjs';
2
+ import { isBrowser } from '../../environment.js';
3
3
  import { RpcEndpoint } from '../rpc-endpoint.js';
4
4
  export class MessagePortRpcEndpoint extends RpcEndpoint {
5
5
  source;
@@ -5,13 +5,12 @@
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
- import type { ReactiveNode } from './graph.js';
9
8
  /**
10
9
  * Symbol used to tell `Signal`s apart from other functions.
11
10
  *
12
11
  * This can be used to auto-unwrap signals in various cases, or to auto-wrap non-signal values.
13
12
  */
14
- declare const SIGNAL: unique symbol;
13
+ export declare const SIGNAL: unique symbol;
15
14
  /**
16
15
  * A reactive value which notifies consumers of any changes.
17
16
  *
@@ -28,21 +27,6 @@ export interface Signal<T> {
28
27
  * Checks if the given `value` is a reactive `Signal`.
29
28
  */
30
29
  export declare function isSignal(value: unknown): value is Signal<unknown>;
31
- /**
32
- * Converts `fn` into a marked signal function (where `isSignal(fn)` will be `true`).
33
- *
34
- * @param fn A zero-argument function which will be converted into a `Signal`.
35
- */
36
- export declare function createSignalFromFunction<T>(node: ReactiveNode, fn: () => T): Signal<T>;
37
- /**
38
- * Converts `fn` into a marked signal function (where `isSignal(fn)` will be `true`), and
39
- * potentially add some set of extra properties (passed as an object record `extraApi`).
40
- *
41
- * @param fn A zero-argument function which will be converted into a `Signal`.
42
- * @param extraApi An object whose properties will be copied onto `fn` in order to create a specific
43
- * desired interface for the `Signal`.
44
- */
45
- export declare function createSignalFromFunction<T, U extends Record<string, unknown>>(node: ReactiveNode, fn: () => T, extraApi: U): Signal<T> & U;
46
30
  /**
47
31
  * A comparison function which can determine if two values are equal.
48
32
  */
@@ -55,4 +39,3 @@ export type ValueEqualityFn<T> = (a: T, b: T) => boolean;
55
39
  * propagate change notification upon explicit mutation without identity change.
56
40
  */
57
41
  export declare function defaultEquals<T>(a: T, b: T): boolean;
58
- export {};
@@ -10,22 +10,13 @@
10
10
  *
11
11
  * This can be used to auto-unwrap signals in various cases, or to auto-wrap non-signal values.
12
12
  */
13
- const SIGNAL = Symbol('SIGNAL');
13
+ export const SIGNAL = Symbol('SIGNAL');
14
14
  /**
15
15
  * Checks if the given `value` is a reactive `Signal`.
16
16
  */
17
17
  export function isSignal(value) {
18
18
  return typeof value === 'function' && value[SIGNAL] !== undefined;
19
19
  }
20
- /**
21
- * Converts `fn` into a marked signal function (where `isSignal(fn)` will be `true`), and
22
- * potentially add some set of extra properties (passed as an object record `extraApi`).
23
- */
24
- export function createSignalFromFunction(node, fn, extraApi = {}) {
25
- fn[SIGNAL] = node;
26
- // Copy properties from `extraApi` to `fn` to complete the desired API of the `Signal`.
27
- return Object.assign(fn, extraApi);
28
- }
29
20
  /**
30
21
  * The default equality function used for `signal` and `computed`, which treats objects and arrays
31
22
  * as never equal, and all other primitive values using identity semantics.
@@ -5,16 +5,27 @@
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
- import { createSignalFromFunction, defaultEquals } from './api.js';
9
- import { ReactiveNode, setActiveConsumer } from './graph.js';
8
+ import { SIGNAL, defaultEquals } from './api.js';
9
+ import { REACTIVE_NODE, consumerAfterComputation, consumerBeforeComputation, producerAccessed, producerUpdateValueVersion } from './graph.js';
10
10
  /**
11
11
  * Create a computed `Signal` which derives a reactive value from an expression.
12
12
  */
13
13
  export function computed(computation, options) {
14
- const node = new ComputedImpl(computation, options?.equal ?? defaultEquals);
15
- // Casting here is required for g3, as TS inference behavior is slightly different between our
16
- // version/options and g3's.
17
- return createSignalFromFunction(node, node.signal.bind(node));
14
+ const node = Object.create(COMPUTED_NODE);
15
+ node.computation = computation;
16
+ options?.equal && (node.equal = options.equal);
17
+ const computed = () => {
18
+ // Check if the value needs updating before returning it.
19
+ producerUpdateValueVersion(node);
20
+ // Record that someone looked at this signal.
21
+ producerAccessed(node);
22
+ if (node.value === ERRORED) {
23
+ throw node.error;
24
+ }
25
+ return node.value;
26
+ };
27
+ computed[SIGNAL] = node;
28
+ return computed;
18
29
  }
19
30
  /**
20
31
  * A dedicated symbol used before a computed value has been calculated for the first time.
@@ -33,107 +44,44 @@ const COMPUTING = Symbol('COMPUTING');
33
44
  * Explicitly typed as `any` so we can use it as signal's value.
34
45
  */
35
46
  const ERRORED = Symbol('ERRORED');
36
- /**
37
- * A computation, which derives a value from a declarative reactive expression.
38
- *
39
- * `Computed`s are both producers and consumers of reactivity.
40
- */
41
- class ComputedImpl extends ReactiveNode {
42
- computation;
43
- equal;
44
- constructor(computation, equal) {
45
- super();
46
- this.computation = computation;
47
- this.equal = equal;
48
- }
49
- /**
50
- * Current value of the computation.
51
- *
52
- * This can also be one of the special values `UNSET`, `COMPUTING`, or `ERRORED`.
53
- */
54
- value = UNSET;
55
- /**
56
- * If `value` is `ERRORED`, the error caught from the last computation attempt which will
57
- * be re-thrown.
58
- */
59
- error = null;
60
- /**
61
- * Flag indicating that the computation is currently stale, meaning that one of the
62
- * dependencies has notified of a potential change.
63
- *
64
- * It's possible that no dependency has _actually_ changed, in which case the `stale`
65
- * state can be resolved without recomputing the value.
66
- */
67
- stale = true;
68
- consumerAllowSignalWrites = false;
69
- onConsumerDependencyMayHaveChanged() {
70
- if (this.stale) {
71
- // We've already notified consumers that this value has potentially changed.
72
- return;
73
- }
74
- // Record that the currently cached value may be stale.
75
- this.stale = true;
76
- // Notify any consumers about the potential change.
77
- this.producerMayHaveChanged();
78
- }
79
- onProducerUpdateValueVersion() {
80
- if (!this.stale) {
81
- // The current value and its version are already up to date.
82
- return;
83
- }
84
- // The current value is stale. Check whether we need to produce a new one.
85
- if (this.value !== UNSET && this.value !== COMPUTING &&
86
- !this.consumerPollProducersForChange()) {
87
- // Even though we were previously notified of a potential dependency update, all of
88
- // our dependencies report that they have not actually changed in value, so we can
89
- // resolve the stale state without needing to recompute the current value.
90
- this.stale = false;
91
- return;
92
- }
93
- // The current value is stale, and needs to be recomputed. It still may not change -
94
- // that depends on whether the newly computed value is equal to the old.
95
- this.recomputeValue();
96
- }
97
- recomputeValue() {
98
- if (this.value === COMPUTING) {
47
+ const COMPUTED_NODE = {
48
+ ...REACTIVE_NODE,
49
+ value: UNSET,
50
+ dirty: true,
51
+ error: null,
52
+ equal: defaultEquals,
53
+ producerMustRecompute(node) {
54
+ // Force a recomputation if there's no current value, or if the current value is in the process
55
+ // of being calculated (which should throw an error).
56
+ return node.value === UNSET || node.value === COMPUTING;
57
+ },
58
+ producerRecomputeValue(node) {
59
+ if (node.value === COMPUTING) {
99
60
  // Our computation somehow led to a cyclic read of itself.
100
61
  throw new Error('Detected cycle in computations.');
101
62
  }
102
- const oldValue = this.value;
103
- this.value = COMPUTING;
104
- // As we're re-running the computation, update our dependent tracking version number.
105
- this.trackingVersion++;
106
- const prevConsumer = setActiveConsumer(this);
63
+ const oldValue = node.value;
64
+ node.value = COMPUTING;
65
+ const prevConsumer = consumerBeforeComputation(node);
107
66
  let newValue;
108
67
  try {
109
- newValue = this.computation();
68
+ newValue = node.computation();
110
69
  }
111
70
  catch (err) {
112
71
  newValue = ERRORED;
113
- this.error = err;
72
+ node.error = err;
114
73
  }
115
74
  finally {
116
- setActiveConsumer(prevConsumer);
75
+ consumerAfterComputation(node, prevConsumer);
117
76
  }
118
- this.stale = false;
119
77
  if (oldValue !== UNSET && oldValue !== ERRORED && newValue !== ERRORED &&
120
- this.equal(oldValue, newValue)) {
78
+ node.equal(oldValue, newValue)) {
121
79
  // No change to `valueVersion` - old and new values are
122
80
  // semantically equivalent.
123
- this.value = oldValue;
81
+ node.value = oldValue;
124
82
  return;
125
83
  }
126
- this.value = newValue;
127
- this.valueVersion++;
128
- }
129
- signal() {
130
- // Check if the value needs updating before returning it.
131
- this.onProducerUpdateValueVersion();
132
- // Record that someone looked at this signal.
133
- this.producerAccessed();
134
- if (this.value === ERRORED) {
135
- throw this.error;
136
- }
137
- return this.value;
138
- }
139
- }
84
+ node.value = newValue;
85
+ node.version++;
86
+ },
87
+ };
@@ -22,7 +22,7 @@ export declare class EffectManager {
22
22
  private readonly all;
23
23
  private readonly queue;
24
24
  private pendingFlush;
25
- create(effectFn: (onCleanup: (cleanupFn: EffectCleanupFn) => void) => void, { allowSignalWrites }?: CreateEffectOptions): EffectRef;
25
+ create(effectFn: (onCleanup: (cleanupFn: EffectCleanupFn) => void) => void, allowSignalWrites: boolean): EffectRef;
26
26
  flush(): void;
27
27
  get isQueueEmpty(): boolean;
28
28
  }