Skip to content

Commit 2f23bd6

Browse files
authored
Merge pull request #694 from adopted-ember-addons/named-exports
Provide helpers named exports for Template Tag support
2 parents 029eb6e + 51653d1 commit 2f23bd6

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

README.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,26 @@ If you are only accessing keys in an object that is only one level deep, you do
201201
</form>
202202
```
203203

204+
### Template Tag support
205+
206+
For usage in [Template Tag Format](https://guides.emberjs.com/release/components/template-tag-format/),
207+
this addon provides `changesetGet` and `changesetSet` named exports:
208+
209+
```gjs
210+
import { changesetGet, changesetSet } from 'ember-changeset';
211+
212+
export default <template>
213+
<form>
214+
<FormInput
215+
id="first-name"
216+
type="text"
217+
@value={{changesetGet @changeset "person.firstName"}}
218+
@onChange={{changesetSet @changeset "person.firstName"}}
219+
/>
220+
</form>
221+
</template>
222+
```
223+
204224
## Limiting which keys dirty the changeset
205225

206226
In order to limit the changes made to your changeset and it's associated `isDirty` state, you can pass in a list of `changesetKeys`.
@@ -226,7 +246,7 @@ let changeset = Changeset(model, validatorFn, validationMap, { skipValidate: tru
226246

227247
Be sure to call `validate()` on the `changeset` before saving or committing changes.
228248

229-
## Types
249+
## TypesScript
230250

231251
```ts
232252
import Component from '@glimmer/component';
@@ -256,6 +276,27 @@ Other available types include the following. Please put in a PR if you need more
256276
import type { ValidationResult, ValidatorMapFunc, ValidatorAction } from 'ember-changeset/types';
257277
```
258278

279+
This project ships [Glint](https://github.com/typed-ember/glint) types,
280+
which allow you when using TypeScript to get strict type checking in your templates.
281+
282+
Unless you are using [strict mode](http://emberjs.github.io/rfcs/0496-handlebars-strict-mode.html) templates
283+
(via [first class component templates](http://emberjs.github.io/rfcs/0779-first-class-component-templates.html)),
284+
Glint needs a [Template Registry](https://typed-ember.gitbook.io/glint/using-glint/ember/template-registry)
285+
that contains entries for the template helper provided by this addon.
286+
To add these registry entries automatically to your app, you just need to import `ember-changeset/template-registry`
287+
from somewhere in your app. When using Glint already, you will likely have a file like
288+
`types/glint.d.ts` where you already import glint types, so just add the import there:
289+
290+
```ts
291+
import '@glint/environment-ember-loose';
292+
import type ChangesetRegistry from 'ember-changeset/template-registry';
293+
declare module '@glint/environment-ember-loose/registry' {
294+
export default interface Registry extends ChangesetRegistry, /* other addon registries */ {
295+
// local entries
296+
}
297+
}
298+
```
299+
259300
## Alternative Changeset
260301

261302
Enabled in 4.1.0. Experimental and subject to changes until 5.0.

addon/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import {
1616
} from '@embroider/macros';
1717

1818
export { ValidatedChangeset };
19+
export { default as changesetGet } from './helpers/changeset-get';
20+
export { default as changesetSet } from './helpers/changeset-set';
1921

2022
const CHANGES = '_changes';
2123
const PREVIOUS_CONTENT = '_previousContent';

0 commit comments

Comments
 (0)