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

[DOC release] Update documentation for tracked with classic classes #18735

Merged
merged 1 commit into from
Feb 11, 2020
Merged
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
32 changes: 32 additions & 0 deletions packages/@ember/-internals/glimmer/lib/glimmer-tracking-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,38 @@
}
```

`tracked` can also be used with the classic Ember object model in a similar
manner to classic computed properties:

```javascript
import EmberObject from '@ember/object';
import { tracked } from '@glimmer/tracking';

const Entry = EmberObject.extend({
name: tracked(),
phoneNumber: tracked()
});
```

Often this is unnecessary, but to ensure robust auto-tracking behavior it is
advisable to mark tracked state appropriately wherever possible.

This form of `tracked` also accepts an optional configuration object
containing either an initial `value` or an `initializer` function (but not
both).

```javascript
import EmberObject from '@ember/object';
import { tracked } from '@glimmer/tracking';

const Entry = EmberObject.extend({
name: tracked({ value: 'Zoey' }),
favoriteSongs: tracked({
initializer: () => ['Raspberry Beret', 'Time After Time']
})
});
```

@method tracked
@static
@for @glimmer/tracking
Expand Down