Usage
import { noop } from 'ngwr/utils';
class MyService {
private onChange: (v: string) => void = noop;
}Why ngwr provides this
Inline () => {} defaults look harmless, but each call site / class instance creates a fresh function reference. That breaks === equality across renders and triggers unnecessary OnPush updates / @Input change-detection cycles. noop is a single shared reference — the comparison stays stable.
// Native — each instance gets a fresh arrow, breaking ref equality.
class MyComponent {
// `() => {}` here creates a new function per instance.
onChange = () => {};
}
// → OnPush comparing `onChange` between renders sees "changed" every time.
// ngwr — single shared function reference; ref equality is stable.
class MyComponent {
onChange = noop;
}API
| Name | Description | Type | Default |
|---|---|---|---|
noop() | No-op function. Use as default for required callback slots. | () => void | — |