Skip to content

Commit ae1438b

Browse files
committed
updates
1 parent d1f23d3 commit ae1438b

13 files changed

+35
-316
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77
**If this PR should not be merged upon approval for any reason, please submit as a DRAFT**
88

99
Which product(s) are affected by this PR (if applicable)?
10-
1110
- [ ] amplify-cli
1211
- [ ] amplify-ui
1312
- [ ] amplify-studio
1413
- [ ] amplify-hosting
1514
- [ ] amplify-libraries
1615

1716
Which platform(s) are affected by this PR (if applicable)?
18-
1917
- [ ] JS
2018
- [ ] iOS
2119
- [ ] Android
@@ -32,12 +30,11 @@ Which platform(s) are affected by this PR (if applicable)?
3230

3331
- [ ] Are any files being deleted with this PR? If so, have the needed redirects been created?
3432

35-
- [ ] Are all links in MDX files using the MDX link syntax rather than HTML link syntax? <br /> _ref: MDX: `[link](https://link.com)` HTML: `<a href="https://link.com">link</a>`_
36-
37-
- [ ] Does this PR include new and / or updated code examples? If so, please add E2E tests for those samples and link them in this PR.
33+
- [ ] Are all links in MDX files using the MDX link syntax rather than HTML link syntax? <br />
34+
_ref: MDX: `[link](https://link.com)`
35+
HTML: `<a href="https://link.com">link</a>`_
3836

3937
### When this PR is ready to merge, please check the box below
40-
4138
- [ ] Ready to merge
4239

4340
_By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license._

src/fragments/lib/datastore/js/conflict.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ DataStore.configure({
5151
},
5252
conflictHandler: async (data) => {
5353
// Example conflict handler
54-
5554
const modelConstructor = data.modelConstructor;
5655
if (modelConstructor === Post) {
5756
const remoteModel = data.remoteModel;

src/fragments/lib/datastore/js/data-access/delete-snippet.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
```ts
55
const toDelete = await DataStore.query(Post, '1234567');
6-
if (!toDelete) return;
7-
DataStore.delete(toDelete);
6+
if (toDelete) {
7+
DataStore.delete(toDelete);
8+
}
89
```
910

1011
</Block>

src/fragments/lib/datastore/js/data-access/observe-update-snippet.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function App() {
6161
value="Save"
6262
onClick={async () => {
6363
/**
64-
* This post is already up to date because observeQuery updated it.
64+
* This post is already up-to-date because `observeQuery` updated it.
6565
*/
6666
if (!post) return;
6767
await DataStore.save(post);
Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,8 @@
11
When using multiple conditions, you can wrap the predicates with the `and` operator. For example with multiple conditions:
22

3-
<BlockSwitcher>
4-
<Block name="TypeScript">
5-
6-
```ts
7-
const posts: Post[] = await DataStore.query<Post>(Post, (c) => c.and(c => [
8-
c.rating.gt(4),
9-
c.status.eq(PostStatus.ACTIVE)
10-
]));
11-
```
12-
13-
</Block>
14-
<Block name="JavaScript">
15-
163
```js
174
const posts = await DataStore.query(Post, (c) => c.and(c => [
185
c.rating.gt(4),
196
c.status.eq(PostStatus.ACTIVE)
207
]));
21-
```
22-
23-
</Block>
24-
</BlockSwitcher>
8+
```
Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
1-
<BlockSwitcher>
2-
<Block name="TypeScript">
3-
4-
```ts
5-
const posts: Post[] = await DataStore.query<Post>(Post, Predicates.ALL, {
6-
sort: s => s.rating(SortDirection.ASCENDING).title(SortDirection.DESCENDING)
7-
});
8-
```
9-
10-
</Block>
11-
<Block name="JavaScript">
12-
131
```js
142
const posts = await DataStore.query(Post, Predicates.ALL, {
15-
sort: s => s.rating(SortDirection.ASCENDING).title(SortDirection.DESCENDING)
3+
sort: (s) => s.rating(SortDirection.ASCENDING).title(SortDirection.DESCENDING)
164
});
175
```
18-
19-
</Block>
20-
</BlockSwitcher>
Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
<BlockSwitcher>
2-
<Block name="TypeScript">
3-
4-
```ts
5-
await DataStore.save(
6-
new Post<Post>({
7-
title: 'My First Post',
8-
rating: 10,
9-
status: PostStatus.INACTIVE
10-
})
11-
);
12-
```
13-
14-
</Block>
15-
<Block name="JavaScript">
16-
171
```js
182
await DataStore.save(
193
new Post({
@@ -22,7 +6,4 @@ await DataStore.save(
226
status: PostStatus.INACTIVE
237
})
248
);
25-
```
26-
27-
</Block>
28-
</BlockSwitcher>
9+
```

src/fragments/lib/datastore/js/data-access/update-snippet.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
async function updatePost(id, newTitle) {
66
const original = await DataStore.query(Post, id);
77

8-
if (!original) return;
9-
10-
const updatedPost = await DataStore.save(
11-
Post.copyOf(original, updated => {
12-
updated.title = newTitle
13-
})
14-
);
8+
if (original) {
9+
const updatedPost = await DataStore.save(
10+
Post.copyOf(original, updated => {
11+
updated.title = newTitle
12+
})
13+
);
14+
}
1515
}
1616
```
1717

src/fragments/lib/datastore/js/examples.mdx

Lines changed: 0 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
## Example application
22

3-
<BlockSwitcher>
4-
<Block name="React (JS)">
5-
63
```jsx
74
import React, { useEffect } from "react";
85
import logo from "./logo.svg";
@@ -71,189 +68,6 @@ function App() {
7168

7269
export default App;
7370
```
74-
</Block>
75-
<Block name="React (TS)">
76-
77-
```ts
78-
import React, { useEffect } from "react";
79-
import logo from "./logo.svg";
80-
import "./App.css";
81-
82-
import { Amplify, DataStore, Predicates } from "aws-amplify";
83-
import { Post, PostStatus } from "./models";
84-
85-
// Use next two lines only if syncing with the cloud
86-
import awsconfig from "./aws-exports";
87-
Amplify.configure(awsconfig);
88-
89-
function onCreate() {
90-
DataStore.save<Post>(
91-
new Post({
92-
title: `New title ${Date.now()}`,
93-
rating: Math.floor(Math.random() * (8 - 1) + 1),
94-
status: PostStatus.ACTIVE,
95-
})
96-
);
97-
}
98-
99-
function onDeleteAll() {
100-
DataStore.delete(Post, Predicates.ALL);
101-
}
102-
103-
async function onQuery() {
104-
const posts: Post[] = await DataStore.query<Post>(Post, (c) => c.rating.gt(4));
105-
106-
console.log(posts);
107-
}
108-
109-
function App() {
110-
useEffect(() => {
111-
const subscription = DataStore.observe<Post>(Post).subscribe((msg) => {
112-
console.log(msg.model, msg.opType, msg.element);
113-
});
114-
115-
return () => subscription.unsubscribe();
116-
}, []);
117-
118-
return (
119-
<div className="App">
120-
<header className="App-header">
121-
<img src={logo} className="App-logo" alt="logo" />
122-
<div>
123-
<input type="button" value="NEW" onClick={onCreate} />
124-
<input type="button" value="DELETE ALL" onClick={onDeleteAll} />
125-
<input type="button" value="QUERY rating > 4" onClick={onQuery} />
126-
</div>
127-
<p>
128-
Edit <code>src/App.js</code> and save to reload.
129-
</p>
130-
<a
131-
className="App-link"
132-
href="https://reactjs.org"
133-
target="_blank"
134-
rel="noopener noreferrer"
135-
>
136-
Learn React
137-
</a>
138-
</header>
139-
</div>
140-
);
141-
}
142-
143-
export default App;
144-
```
145-
</Block>
146-
<Block name="Angular">
147-
148-
```ts
149-
import { Component, OnInit, OnDestroy } from '@angular/core';
150-
import { DataStore, Predicates } from "aws-amplify";
151-
import { Post, PostStatus } from "./models";
152-
153-
@Component({
154-
selector: 'app-root',
155-
template: `
156-
<div class="app-header">
157-
<button type="button" (click)="onCreate()">NEW</button>
158-
<button type="button" (click)="onDeleteAll()">DELETE ALL</button>
159-
<button type="button" (click)="onQuery()">QUERY rating > 4</button>
160-
</div>
161-
`})
162-
export class AppComponent implements OnInit, OnDestroy {
163-
subscription;
164-
165-
ngOnInit() {
166-
//Subscribe to changes
167-
this.subscription = DataStore.observe<Post>(Post).subscribe((msg) => {
168-
console.log(msg.model, msg.opType, msg.element);
169-
});
170-
}
171-
172-
ngOnDestroy() {
173-
if (!this.subscription) return;
174-
this.subscription.unsubscribe();
175-
}
176-
177-
public async loadPosts() {
178-
let posts = await DataStore.query(Post, (c) => c.rating.gt(4));
179-
console.log(posts);
180-
}
181-
182-
public onCreate() {
183-
DataStore.save(
184-
new Post({
185-
title: `New title ${Date.now()}`,
186-
rating: Math.floor(Math.random() * (8 - 1) + 1),
187-
status: PostStatus.ACTIVE,
188-
})
189-
);
190-
}
191-
192-
public onDeleteAll() {
193-
DataStore.delete(Post, Predicates.ALL);
194-
}
195-
}
196-
```
197-
</Block>
198-
199-
<Block name="Vue">
200-
201-
```javascript
202-
<template>
203-
<div id="app">
204-
<div class="app-body">
205-
<button type="button" @click="onCreate" >NEW</button>
206-
<button type="button" @click="onDeleteAll" >DELETE ALL</button>
207-
<button type="button" @click="onQuery" >QUERY rating > 4</button>
208-
</div>
209-
</div>
210-
</template>
211-
212-
<script>
213-
import { DataStore, Predicates } from "aws-amplify";
214-
import { Post, PostStatus } from "./models";
215-
216-
export default {
217-
name: "app",
218-
data() {
219-
return {
220-
subscription: undefined,
221-
};
222-
},
223-
created() {
224-
//Subscribe to changes
225-
this.subscription = DataStore.observe(Post).subscribe(msg => {
226-
console.log(msg.model, msg.opType, msg.element);
227-
});
228-
},
229-
destroyed() {
230-
if (!this.subscription) return;
231-
this.subscription.unsubscribe();
232-
},
233-
methods: {
234-
async onQuery() {
235-
let posts = await DataStore.query(Post, (c) => c.rating.gt(4));
236-
console.log(posts);
237-
},
238-
onCreate() {
239-
DataStore.save(
240-
new Post({
241-
title: `New title ${Date.now()}`,
242-
rating: Math.floor(Math.random() * (8 - 1) + 1),
243-
status: PostStatus.ACTIVE,
244-
})
245-
);
246-
},
247-
deleteAll() {
248-
DataStore.delete(Post, Predicates.ALL);
249-
}
250-
}
251-
};
252-
</script>
253-
```
254-
</Block>
255-
256-
</BlockSwitcher>
25771

25872
## API Reference
25973

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,8 @@
1-
<BlockSwitcher>
2-
<Block name="TypeScript">
3-
4-
```ts
5-
try {
6-
const posts: Post[] = await DataStore.query<Post>(Post);
7-
console.log("Posts retrieved successfully!", JSON.stringify(posts, null, 2));
8-
} catch (error) {
9-
console.log("Error retrieving posts", error);
10-
}
11-
```
12-
13-
</Block>
14-
<Block name="JavaScript">
15-
161
```js
172
try {
183
const posts = await DataStore.query(Post);
19-
console.log("Posts retrieved successfully!", JSON.stringify(posts, null, 2));
4+
console.log('Posts retrieved successfully!', JSON.stringify(posts, null, 2));
205
} catch (error) {
21-
console.log("Error retrieving posts", error);
6+
console.log('Error retrieving posts', error);
227
}
238
```
24-
25-
</Block>
26-
</BlockSwitcher>
27-

0 commit comments

Comments
 (0)