Skip to content

Commit

Permalink
Update meta
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Jan 19, 2025
1 parent 4eb7776 commit c0b20b6
Showing 1 changed file with 72 additions and 1 deletion.
73 changes: 72 additions & 1 deletion text/0000-cell.md → text/1071-cell.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ teams: # delete teams that aren't relevant
- steering
- typescript
prs:
accepted: # Fill this in with the URL for the Proposal RFC PR
accepted: https://github.com/emberjs/rfcs/pull/1071
project-link:
suite:
---
Expand Down Expand Up @@ -140,9 +140,80 @@ const increment => count.current++;
</template>
```

Using private mutable properties providing public read-only access:

```gjs
export class MyAPI {
#state = Cell.create(0);
get myValue() {
return this.#state;
}
doTheThing() {
this.#state = secretFunctionFromSomewhere();
}
}
```


### Re-implementing `@tracked`

For most current ember projects, using the TC39 Stage 1 implementation of decorators:

```js
function tracked(target, key, { initializer }) {
let cells = new WeakMap();

function getCell(obj) {
let cell = cells.get(obj);

if (cell === undefined) {
cell = Cell.create(initializer.call(this), () => false);
cells.set(this, cell);
}

return cell;
};

return {
get() {
return getCell(this).read();
},

set(value) {
getCell(this).set(value);
},
};
}
```

<details><summary>Using spec / standards-decorators</summary>

```js
import { Cell } from '@glimmer/tracking';

export function tracked(target, context) {
const { get } = target;

return {
get() {
return get.call(this).read();
},

set(value) {
get.call(this).set(value);
},

init(value) {
return Cell.create(value);
},
};
}
```

</details>


## How we teach this

Expand Down

0 comments on commit c0b20b6

Please sign in to comment.