@zibuthe7j11/at-nobis-nulla
Version:
Extract the getter dependencies from object.
48 lines (33 loc) • 1.05 kB
Markdown
Extract the getter dependencies from object.
```bash
npm i @zibuthe7j11/at-nobis-nulla
```
```ts
import { detectGetterDeps } from '@zibuthe7j11/at-nobis-nulla';
const dependencies = detectGetterDeps({
firstName: 'jeans',
lastName: 'new',
get fullName() {
return [this.firstName, this.lastName].join(' ');
},
});
dependencies.get('fullName'); // Set { 'firstName', 'lastName' }
```
This is useful when you want to know which properties are used in the getter.
If there are conditional evaluation rules within the getter body, it may not work properly because there could be properties that are not accessed depending on the object state conditions.
```ts
import { detectGetterDeps } from '@zibuthe7j11/at-nobis-nulla';
const dependencies = detectGetterDeps({
realName: 'deno',
alias: 'saurus',
get name() {
return this.alias || this.realName;
},
});
dependencies.get('name'); // Set { 'alias' }, not Set { 'alias', 'realName' }
```