Coder Social home page Coder Social logo

Comments (3)

jsnanigans avatar jsnanigans commented on July 22, 2024 1

Hey @Rukkaitto thanks for trying out this project!
I'm super excited to get the first issue,
You already closed it, but I will add an answer for others who might come along:

You are probably using the normal method definition like:

class X extends Cubit {
    //...
    someMethod() {
        this.emit(newState);
    }
}

The issue is the same as in classic react class components where you need to bind the method, but the easyest solution is:

turn that into an arrow function:

class X extends Cubit {
    //...
    someMethod = () => {
        this.emit(newState);
    }
}

from blac.

sudoFerraz avatar sudoFerraz commented on July 22, 2024

@jsnanigans Is it possible to use this.emit outside of the constructor of a bloc?

from blac.

jsnanigans avatar jsnanigans commented on July 22, 2024

@sudoFerraz in a Bloc there is no this.emit thats only available in a Cubit.

for a bloc you would want to use this.on to add a listener for an event, then in there you can use the emit method you get in the callback, so if you need this.emit then you should consider using a Cubit

Example for a Cubit can be found here: https://blac-docs.vercel.app/docs/quickstart#create-a-cubit

here is an example of a Bloc:

export enum AuthEvent {
  unknown = "unknown",
  authenticated = "authenticated",
  unauthenticated = "unauthenticated",
}

export default class AuthBloc extends Bloc<AuthEvent, boolean> {
  constructor() {
    super(false)

    this.on(AuthEvent.unknown, (_, emit) => {
      emit(false);
    })
    this.on(AuthEvent.unauthenticated, (_, emit) => {
      emit(false);
    })
    this.on(AuthEvent.authenticated, (_, emit) => {
      emit(true);
    })
  };
}

from blac.

Related Issues (6)

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.