Comments (3)
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.
@jsnanigans Is it possible to use this.emit outside of the constructor of a bloc?
from blac.
@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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blac.