Skip to content

Commit 9f0707b

Browse files
committed
adjust examples
1 parent 864f5cd commit 9f0707b

File tree

1 file changed

+12
-8
lines changed
  • 17/umbraco-cms/customizing/foundation/repositories

1 file changed

+12
-8
lines changed

17/umbraco-cms/customizing/foundation/repositories/README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,33 +33,32 @@ Often, you will find that data is already available and observable in a [context
3333

3434
When a context with the appropriate data state is not available, reaching for a repository will ensure access to the needed data no matter the current application state.
3535

36-
In the example below, we instantiate the `UmbDocumentItemRepository` directly in a custom element to request Document data by its unique key.
36+
In the example below, we instantiate the `UmbDocumentItemRepository` directly in a custom element to request Document Item data by its unique key.
3737

3838
```typescript
3939
import { LitElement} from '@umbraco-cms/backoffice/external/lit';
4040
import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api';
4141
import { UmbDocumentItemRepository } from '@umbraco-cms/backoffice/document';
4242

43+
// Simplified element
4344
class MyElement extends UmbElementMixin(LitElement) {
4445
...
4546
#documentItemRepository = new UmbDocumentItemRepository(this);
4647

4748
firstUpdated() {
4849
const { data, error } = await this.#documentItemRepository.requestItems(['some-unique-key', 'another-unique-key']);
49-
console.log('The Document Items:', data);
50+
console.log('Response', data, error);
5051
// Render data in the element
5152
}
5253
...
5354
}
54-
55-
const documentRepository = new UmbDocumentDetailRepository(this);
5655
```
5756

58-
Alternatively, you can instantiate the repository in a [controller](..) or [context](../../context-api/README.md), store it in a [state](../states.md), and then consume that context in your element. This is often the preferred approach as it allows for better separation of concerns and reusability across different components.
57+
Alternatively, you can instantiate the repository in a [controller](..) or [context](../../context-api/README.md), store it in a [state](../states.md), and then use that state in your element. This is often the preferred approach as it allows for better separation of concerns and reusability across different components.
5958

6059
```typescript
6160
import { UmbArrayState } from '@umbraco-cms/backoffice/observable-api';
62-
import { UmbControllerBase } from '@umbraco-cms/backoffice/context-api';
61+
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
6362
import { UmbDocumentItemRepository } from '@umbraco-cms/backoffice/document';
6463

6564
export class MyController extends UmbControllerBase {
@@ -69,9 +68,14 @@ export class MyController extends UmbControllerBase {
6968

7069
#documentItemRepository = new UmbDocumentItemRepository(this);
7170

72-
load() {
71+
constructor(host: UmbControllerHost) {
72+
super(host);
73+
this.#load();
74+
}
75+
76+
async #load() {
7377
const { data, error } = await this.#documentItemRepository.requestItems(['some-unique-key', 'another-unique-key']);
74-
console.log('The Document Items:', data);
78+
console.log('Response', data, error);
7579
this.#items.setValue(data ?? []);
7680
// The items state can now be observed by any element initializing this controller
7781
}

0 commit comments

Comments
 (0)