Skip to content

Commit d0beb5b

Browse files
committed
updated examples in readme
1 parent 698ca94 commit d0beb5b

File tree

1 file changed

+16
-11
lines changed
  • packages/redux-controller-middleware

1 file changed

+16
-11
lines changed

packages/redux-controller-middleware/README.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,14 @@ class UsersController extends ControllerBase<UsersSlice, { users: UsersSlice }>
182182

183183
@reducer
184184
async addUser(action: Action<{ name: string }>) {
185-
const newUser = await Promise.resolve().then(() => ({
186-
userId: new Date().valueOf().toString(),
187-
userName: action.payload.name,
188-
}));
185+
const newUserResponse = await fetch('/api/user', {
186+
method: 'POST',
187+
body: JSON.stringify({
188+
username: action.payload.name
189+
})
190+
});
191+
192+
const newUser = await newUserResponse.json();
189193

190194
const { usersList } = this.getState().users;
191195

@@ -253,12 +257,12 @@ export class Logger {
253257
}
254258

255259
export class UserApi {
256-
constructor(private logger: Logger) {
257-
}
260+
constructor(private logger: Logger) {}
258261

259262
async get() {
260263
this.logger.log('[my api] fetching users list');
261-
return ['user-1', 'user-2'];
264+
const response = await fetch('/api/user');
265+
return response.json();
262266
}
263267
}
264268
// services.ts
@@ -276,17 +280,17 @@ export class Logger {
276280

277281
@inject(Logger)
278282
export class UserApi {
279-
constructor(private logger: Logger) {
280-
}
283+
constructor(private logger: Logger) {}
281284

282285
async get() {
283286
this.logger.log('[my api] fetching users list');
284-
return ['user-1', 'user-2'];
287+
const response = await fetch('/api/user');
288+
return response.json();
285289
}
286290
}
287291
```
288292

289-
> **_NOTE:_** you need to adjust tsconfig.json to use stage 2 decorators:
293+
> **_NOTE:_** To use stage 2 decorators, you need to adjust your tsconfig.json like this:
290294
> ```json
291295
> {
292296
> "compilerOptions": {
@@ -295,6 +299,7 @@ export class UserApi {
295299
> }
296300
> }
297301
> ```
302+
> To use stage 3 decorators, you don't need extra setup.
298303
299304
### <a name="dependency-injection-functional"></a> Functional variant
300305

0 commit comments

Comments
 (0)