Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves https://github.com/tc39/proposal-signals/issues/174 #175

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions packages/signal-polyfill/src/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/

// Required as the signals library is in a separate package, so we need to explicitly ensure the
// global `ngDevMode` type is defined.
declare const ngDevMode: boolean|undefined;


/**
* The currently active consumer `ReactiveNode`, if running code in a reactive context.
*
Expand Down Expand Up @@ -215,7 +210,7 @@ interface ProducerNode extends ReactiveNode {
export function producerAccessed(node: ReactiveNode): void {
if (inNotificationPhase) {
throw new Error(
typeof ngDevMode !== 'undefined' && ngDevMode ?
import.meta?.env?.DEBUG ?
`Assertion error: signal read during notification phase` :
'');
}
Expand Down Expand Up @@ -462,7 +457,7 @@ export function producerRemoveLiveConsumerAtIndex(node: ReactiveNode, idx: numbe
assertProducerNode(node);
assertConsumerNode(node);

if (typeof ngDevMode !== 'undefined' && ngDevMode && idx >= node.liveConsumerNode.length) {
if (import.meta?.env?.DEBUG && idx >= node.liveConsumerNode.length) {
throw new Error(`Assertion error: active consumer index ${idx} is out of bounds of ${
node.liveConsumerNode.length} consumers)`);
}
Expand Down
5 changes: 5 additions & 0 deletions packages/signal-polyfill/src/import-meta-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
interface ImportMeta {
env?: {
DEBUG?: boolean;
};
}
4 changes: 0 additions & 4 deletions packages/signal-polyfill/src/signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import {defaultEquals, ValueEqualityFn} from './equality.js';
import {throwInvalidWriteToSignalError} from './errors.js';
import {producerAccessed, producerIncrementEpoch, producerNotifyConsumers, producerUpdatesAllowed, REACTIVE_NODE, ReactiveNode, SIGNAL} from './graph.js';

// Required as the signals library is in a separate package, so we need to explicitly ensure the
// global `ngDevMode` type is defined.
declare const ngDevMode: boolean|undefined;

/**
* If set, called after `WritableSignal`s are updated.
*
Expand Down
2 changes: 1 addition & 1 deletion packages/signal-polyfill/src/wrapper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1018,5 +1018,5 @@ describe("currentComputed", () => {
// - The code for the callbacks (for reading signals and running watches)
// - Paths around writes being prohibited during computed/effect
// - Setters for various hooks
// - ngDevMode
// - import.meta.env.DEBUG
// - Some predicates/getters for convenience, e.g., isReactive
Loading