redux-app-examples
Version:
Examples of redux-app with Angular and React.
44 lines (35 loc) • 1.22 kB
text/typescript
import { action, sequence } from 'redux-app';
export class App {
public title = "async dogs";
public subtitle = "using the sequence decorator, an async pattern that does not require thunks";
public status = 'click the button...';
public imageUrl: string = null;
public counter = 0;
public updateImageUrl(url: string) {
this.imageUrl = url;
}
public setStatus(newStatus: string) {
this.status = newStatus;
}
public async fetchImage() { // <--- this is the most interesting part of the code
this.setStatus('Fetching...');
var response = await fetch('https://dog.ceo/api/breeds/image/random');
var responseBody = await response.json();
this.setStatus('Adding unnecessary delay...');
setTimeout(() => {
this.updateImageUrl(responseBody.message);
this.setStatus('walla!');
}, 2000);
}
public increment() {
console.log('business as usual');
this.counter = this.counter + 1;
}
public async doNothing() {
console.log('ignore me...');
}
}