felangel / bloc.js

A predictable state management library that helps implement the BLoC design pattern in JavaScript
https://bloclibrary.dev
189 stars 22 forks source link

feat: modern implementation #107

Open jacobtipp opened 1 year ago

jacobtipp commented 1 year ago

Status

IN DEVELOPMENT

Breaking Changes

YES

Description

Update API to reflect modern v8.x Dart implementation

Type of Change

erickjtorres commented 1 year ago

LGTM

jacobtipp commented 1 year ago

LGTM

I changed the node engine compatibility from version 6 to 14. I believe this is why the CI was failing, as it was running node version 10. Most newer packages support node v14+ only nowadays. Also I have marked this pull request as a draft. I still need to add Cubit/Bloc and their respective tests.

jacobtipp commented 1 year ago

These are some big changes. I've tried to keep the implementation as close as possible to the original with 100% code coverage.

Some things to note related to Typescript, JavaScript, and limitations:

felangel commented 1 year ago

These are some big changes. I've tried to keep the implementation as close as possible to the original with 100% code coverage.

Some things to note related to Typescript, JavaScript, and limitations:

  • Events must be classes. Which means enums can't be used as events. It is discouraged to use enums in Typescript because they aren't native to JavaScript and will require extra code to be compiled to mimic it's behavior at runtime. Using es6 classes for bloc events makes more sense and gives us consistency. Use discriminated unions instead of enums whenever possible.
  • Typescript doesn't have callabale classes. Which means the emitter instance cannot be used as a function. However, in JavaScript, all functions are objects, so I've created a "callable emitter" that simply proxies all calls to the actual emitter instance. This can be seen here

Thanks so much for the huge contribution! I’ll make sure to review this within the next few days 🙏💯

codecov-commenter commented 1 year ago

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (69e71fe) 100.00% compared to head (2c906df) 100.00%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #107 +/- ## ========================================== Coverage 100.00% 100.00% ========================================== Files 1 9 +8 Lines 33 196 +163 Branches 5 12 +7 ========================================== + Hits 33 196 +163 ``` | [Impacted Files](https://app.codecov.io/gh/felangel/bloc.js/pull/107?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Felix+Angelov) | Coverage Δ | | |---|---|---| | [packages/bloc/lib/src/base.ts](https://app.codecov.io/gh/felangel/bloc.js/pull/107?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Felix+Angelov#diff-cGFja2FnZXMvYmxvYy9saWIvc3JjL2Jhc2UudHM=) | `100.00% <100.00%> (ø)` | | | [packages/bloc/lib/src/bloc-observer.ts](https://app.codecov.io/gh/felangel/bloc.js/pull/107?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Felix+Angelov#diff-cGFja2FnZXMvYmxvYy9saWIvc3JjL2Jsb2Mtb2JzZXJ2ZXIudHM=) | `100.00% <100.00%> (ø)` | | | [packages/bloc/lib/src/bloc.ts](https://app.codecov.io/gh/felangel/bloc.js/pull/107?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Felix+Angelov#diff-cGFja2FnZXMvYmxvYy9saWIvc3JjL2Jsb2MudHM=) | `100.00% <100.00%> (ø)` | | | [packages/bloc/lib/src/change.ts](https://app.codecov.io/gh/felangel/bloc.js/pull/107?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Felix+Angelov#diff-cGFja2FnZXMvYmxvYy9saWIvc3JjL2NoYW5nZS50cw==) | `100.00% <100.00%> (ø)` | | | [packages/bloc/lib/src/cubit.ts](https://app.codecov.io/gh/felangel/bloc.js/pull/107?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Felix+Angelov#diff-cGFja2FnZXMvYmxvYy9saWIvc3JjL2N1Yml0LnRz) | `100.00% <100.00%> (ø)` | | | [packages/bloc/lib/src/emitter.ts](https://app.codecov.io/gh/felangel/bloc.js/pull/107?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Felix+Angelov#diff-cGFja2FnZXMvYmxvYy9saWIvc3JjL2VtaXR0ZXIudHM=) | `100.00% <100.00%> (ø)` | | | [packages/bloc/lib/src/event.ts](https://app.codecov.io/gh/felangel/bloc.js/pull/107?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Felix+Angelov#diff-cGFja2FnZXMvYmxvYy9saWIvc3JjL2V2ZW50LnRz) | `100.00% <100.00%> (ø)` | | | [packages/bloc/lib/src/index.ts](https://app.codecov.io/gh/felangel/bloc.js/pull/107?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Felix+Angelov#diff-cGFja2FnZXMvYmxvYy9saWIvc3JjL2luZGV4LnRz) | `100.00% <100.00%> (ø)` | | ... and [2 files with indirect coverage changes](https://app.codecov.io/gh/felangel/bloc.js/pull/107/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Felix+Angelov)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.