ember-learn / ember-learn/guides-source

Document how to update arrays and objects in Ember Octane

Open
#1,539 3 comments 2 reactions 0 assignees View on GitHub
enhancement help wanted Octane
Dominant language
HTML
Stars
161
Forks
512
Avg merge
4d 9h
Merged PRs (30d)
4

Description

## Background

- [Learning Team meeting notes from August 20, 2020](https://github.com/emberjs/core-notes/blob/master/learning-team/2020-08/2020-08-20.md#ember-arrays-vs-native-arrays)
- [A Discord conversation](https://discordapp.com/channels/480462759797063690/480777444203429888/741663906245771294)

## Description

We currently don't describe well how to update tracked arrays and objects in Ember Octane. On Discord, now and then, a developer does ask how they can do so.

```javascript
@tracked myArray = [];
@tracked myObject = {};

@action updateMyArray() {
// How?
}
@action updateMyObject() {
// How?
}
```

- [In-Depth Topics - Autotracking In-Depth - Plain Old JavaScript Objects (POJOs)](https://guides.emberjs.com/release/in-depth-topics/autotracking-in-depth/#toc_plain-old-javascript-objects-pojos)
- [In-Depth Topics - Autotracking In-Depth - Arrays](https://guides.emberjs.com/release/in-depth-topics/autotracking-in-depth/#toc_arrays)
- [Upgrading - Tracked Properties - Plain Old JavaScript Objects (POJOs)](https://guides.emberjs.com/release/upgrading/current-edition/tracked-properties/#toc_plain-old-javascript-objects-pojos)
- [Upgrading - Tracked Properties - Arrays](https://guides.emberjs.com/release/upgrading/current-edition/tracked-properties/#toc_arrays)

## Possible TODOs

### 1. Arrays

- [ ] Create an example (the example may need to depend on the surrounding page context)
- [ ] Explain that Ember does not react to `this.myArray.push(...);`.
- [ ] Explain possible solutions
- immutable approach
- `EmberArray`
- `tracked-built-ins`

### 2. Objects

- [ ] Create an example (the example may need to depend on the surrounding page context)
- [ ] Explain that Ember does not react to `this.myObject.myProperty = ...;`.
- [ ] Explain possible solutions
- immutable approach
- native class
- `tracked-built-ins`

### 3. Backport

Once the changes are approved for `release` directory, backport the changes all the way back to Ember 3.15.

## Questions

- We have 2 pages (Autotracking In-Depth & Tracked Properties) with almost similar content. Can one page refer to another?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.