Skip to content

Commit

Permalink
chore(bloc): 0.3.0 CHANGELOG and example improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel committed Sep 8, 2020
1 parent 8385df2 commit 6837162
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 40 deletions.
13 changes: 13 additions & 0 deletions packages/bloc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# 0.3.0

Feature parity with dart

- **BREAKING**: rename `BlocDelegate` -> `BlocObserver`
- **BREAKING**: remove `BlocSupervisor`
- **BREAKING**: `transformEvents` returns `Observable<Transition<Event, State>>`
- **BREAKING**: remove `initialState` in favor of `super` constructor
- **BREAKING**: rename `Transition` state to `currentState`
- feat: add `transformTransitions`
- refactor: internal implementation improvements
- docs: add inline documentation and return types

# 0.2.3

Internal improvements and documentation updates
Expand Down
2 changes: 1 addition & 1 deletion packages/bloc/example/.prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"tabWidth": 4,
"tabWidth": 2,
"singleQuote": true
}
78 changes: 39 additions & 39 deletions packages/bloc/example/index.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
import { Bloc, BlocObserver, Transition } from '@felangel/bloc';

enum CounterEvent {
increment = 'INCREMENT',
decrement = 'DECREMENT'
increment = 'INCREMENT',
decrement = 'DECREMENT'
}

class MyBlocObserver extends BlocObserver {
onEvent(_: Bloc<any, any>, event: CounterEvent) {
console.log(`added ${event}`);
}
onEvent(_: Bloc<any, any>, event: CounterEvent) {
console.log(`added ${event}`);
}

onTransition(_: Bloc<any, any>, transition: Transition<any, any>) {
console.log(transition);
}
onTransition(_: Bloc<any, any>, transition: Transition<any, any>) {
console.log(transition);
}

onError(_: Bloc<any, any>, error: any) {
console.log(`error: ${error}`);
}
onError(_: Bloc<any, any>, error: any) {
console.log(`error: ${error}`);
}
}

class CounterBloc extends Bloc<CounterEvent, number> {
constructor() {
super(0);
}

async *mapEventToState(event: CounterEvent) {
switch (event) {
case CounterEvent.increment:
await wait(1000); // Simulating Latency
yield this.state + 1;
break;
case CounterEvent.decrement:
await wait(500); // Simulating Latency
yield this.state - 1;
break;
}
constructor() {
super(0);
}

async *mapEventToState(event: CounterEvent) {
switch (event) {
case CounterEvent.increment:
await wait(1000); // Simulating Latency
yield this.state + 1;
break;
case CounterEvent.decrement:
await wait(500); // Simulating Latency
yield this.state - 1;
break;
}
}
}

(async function main() {
Bloc.observer = new MyBlocObserver();
const counterBloc = new CounterBloc();
Bloc.observer = new MyBlocObserver();
const counterBloc = new CounterBloc();

counterBloc.add(CounterEvent.increment);
counterBloc.add(CounterEvent.increment);
counterBloc.add(CounterEvent.increment);
counterBloc.add(CounterEvent.increment);
counterBloc.add(CounterEvent.increment);
counterBloc.add(CounterEvent.increment);

counterBloc.add(CounterEvent.decrement);
counterBloc.add(CounterEvent.decrement);
counterBloc.add(CounterEvent.decrement);
counterBloc.add(CounterEvent.decrement);
counterBloc.add(CounterEvent.decrement);
counterBloc.add(CounterEvent.decrement);
})();

async function wait(ms: number): Promise<void> {
return new Promise<void>((resolve, _) => {
setTimeout(() => {
resolve();
}, ms);
});
return new Promise<void>((resolve, _) => {
setTimeout(() => {
resolve();
}, ms);
});
}

0 comments on commit 6837162

Please sign in to comment.