Skip to content

Commit 84be1e3

Browse files
committed
fix(data): simplify random number generation in docs examples
1 parent 92eaf26 commit 84be1e3

File tree

3 files changed

+7
-36
lines changed

3 files changed

+7
-36
lines changed

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@ function App() {
3232
const post = await DataStore.save(
3333
new Post({
3434
title: `New title ${Date.now()}`,
35-
rating: (function getRandomInt(min, max) {
36-
min = Math.ceil(min);
37-
max = Math.floor(max);
38-
return Math.floor(Math.random() * (max - min)) + min;
39-
})(1, 7),
35+
rating: Math.floor(Math.random() * (8 - 1) + 1),
4036
status: PostStatus.ACTIVE,
4137
})
4238
);
@@ -114,11 +110,7 @@ function App() {
114110
const post: Post = await DataStore.save<Post>(
115111
new Post({
116112
title: `New title ${Date.now()}`,
117-
rating: (function getRandomInt(min, max) {
118-
min = Math.ceil(min);
119-
max = Math.floor(max);
120-
return Math.floor(Math.random() * (max - min)) + min;
121-
})(1, 7),
113+
rating: Math.floor(Math.random() * (8 - 1) + 1),
122114
status: PostStatus.ACTIVE,
123115
})
124116
);

src/fragments/lib/datastore/js/examples-react-native.mdx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@ class App extends Component {
3737
DataStore.save(
3838
new Post({
3939
title: `New Post ${Date.now()}`,
40-
rating: (function getRandomInt(min, max) {
41-
min = Math.ceil(min);
42-
max = Math.floor(max);
43-
// The maximum is exclusive and the minimum is inclusive
44-
return Math.floor(Math.random() * (max - min)) + min;
45-
})(5, 10),
40+
rating: Math.floor(Math.random() * (8 - 1) + 1),
4641
status: PostStatus.ACTIVE
4742
})
4843
);

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

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ function onCreate() {
1919
DataStore.save(
2020
new Post({
2121
title: `New title ${Date.now()}`,
22-
rating: (function getRandomInt(min, max) {
23-
min = Math.ceil(min);
24-
max = Math.floor(max);
25-
return Math.floor(Math.random() * (max - min)) + min;
26-
})(1, 7),
22+
rating: Math.floor(Math.random() * (8 - 1) + 1),
2723
status: PostStatus.ACTIVE,
2824
})
2925
);
@@ -94,11 +90,7 @@ function onCreate() {
9490
DataStore.save<Post>(
9591
new Post({
9692
title: `New title ${Date.now()}`,
97-
rating: (function getRandomInt(min, max) {
98-
min = Math.ceil(min);
99-
max = Math.floor(max);
100-
return Math.floor(Math.random() * (max - min)) + min;
101-
})(1, 7),
93+
rating: Math.floor(Math.random() * (8 - 1) + 1),
10294
status: PostStatus.ACTIVE,
10395
})
10496
);
@@ -191,11 +183,7 @@ export class AppComponent implements OnInit, OnDestroy {
191183
DataStore.save(
192184
new Post({
193185
title: `New title ${Date.now()}`,
194-
rating: (function getRandomInt(min, max) {
195-
min = Math.ceil(min);
196-
max = Math.floor(max);
197-
return Math.floor(Math.random() * (max - min)) + min;
198-
})(1, 7),
186+
rating: Math.floor(Math.random() * (8 - 1) + 1),
199187
status: PostStatus.ACTIVE,
200188
})
201189
);
@@ -251,11 +239,7 @@ export default {
251239
DataStore.save(
252240
new Post({
253241
title: `New title ${Date.now()}`,
254-
rating: (function getRandomInt(min, max) {
255-
min = Math.ceil(min);
256-
max = Math.floor(max);
257-
return Math.floor(Math.random() * (max - min)) + min;
258-
})(1, 7),
242+
rating: Math.floor(Math.random() * (8 - 1) + 1),
259243
status: PostStatus.ACTIVE,
260244
})
261245
);

0 commit comments

Comments
 (0)