Coder Social home page Coder Social logo

Comments (10)

felangel avatar felangel commented on May 16, 2024 1

Hi @JohannesKlauss, thanks for the feedback.

The reason the mapEventToState signature is (S state, E event) is because the state parameter is referring to the current state rather than the new state.

In onTransition as well as the Bloc class type signature the state is referring to the next state (the output of the Bloc).

Also, mapEventToState is inspired by Redux Reducers whose function signature is (S previousState, A action).

A Bloc is described as converting Events to States (<E, S>) ; however, mapEventToState takes the current state and event and returns the new state (S currentState, E event).

Thoughts? Does that help clarify why it's written the way it is?

from bloc.

ThinkDigitalSoftware avatar ThinkDigitalSoftware commented on May 16, 2024 1

Wait. If state is the current state, then it makes sense because it exists before the event does. I really need to study this function

from bloc.

ThinkDigitalSoftware avatar ThinkDigitalSoftware commented on May 16, 2024 1

It would be very clear if the variable was named currentState or oldState, etc

from bloc.

felangel avatar felangel commented on May 16, 2024 1

haha yeah I will rename it and add the documentation for the generic types

from bloc.

felangel avatar felangel commented on May 16, 2024

@JohannesKlauss closing this for now.
Feel free to respond with any comments or concerns and I'll gladly reopen the issue.

from bloc.

ThinkDigitalSoftware avatar ThinkDigitalSoftware commented on May 16, 2024

OK, came to report this as well. It was confusing. Can you add in the docs what the generic types are for? I figured them out, but not after digging.
Like It's not clear what E is, and what S is until later down the code

from bloc.

felangel avatar felangel commented on May 16, 2024

@ThinkDigitalRepair sure I can definitely update the docs. Do you think it makes sense otherwise or do you still feel strongly that it doesn't make sense as is?

from bloc.

ThinkDigitalSoftware avatar ThinkDigitalSoftware commented on May 16, 2024

from bloc.

felangel avatar felangel commented on May 16, 2024

Yes I agree that generally input is coming from the left side but the way I view it is in this case we have two inputs and we're creating a new state object. The two inputs are S currentState and E event. I personally thought it made sense in that order because the currentState precedes the event. Thoughts?

from bloc.

felangel avatar felangel commented on May 16, 2024

changes included in bloc v0.7.4

from bloc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.