Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removing a producer on component also removes eventTrait #3

Closed
Figgg opened this issue Jun 21, 2019 · 0 comments
Closed

removing a producer on component also removes eventTrait #3

Figgg opened this issue Jun 21, 2019 · 0 comments

Comments

@Figgg
Copy link

Figgg commented Jun 21, 2019

When you want to remove a producer on your component, you can use MolAbstractComponentImpl>>forEvents:removeProducer:

forEvents: anEventTrait removeProducer: aProducer

	| producers |
	producers := self eventsSubscribers at: anEventTrait.
	producers isArray 
		ifTrue: [ (self eventsSubscribers at: anEventTrait) remove: aProducer ]
		ifFalse: [ (self eventsSubscribers removeKey: anEventTrait ) ]

However, if you defined a single producer for an eventTrait (if it's not a list of producers), this method will remove the eventTrait key. Which will result in the component forgetting it consumes this kind of events although we just wanted it to stop using some producer.

Reproduce :
Here's an example with a component myComponent consuming SomeEvents events

myComponent getSomeEventsSubscriber. "works"
myComponent forEvents: SomeEvents useProducer: #someProducer.
myComponent forEvents: SomeEvents removeProducer: #someProducer.
myComponent getSomeEventsSubscriber. "bug"

Temporary solution :
replacing this portion of the code :
ifFalse: [ (self eventsSubscribers removeKey: anEventTrait ) ]
with :

ifFalse: [ producers = aProducer
	ifTrue: [ self eventsSubscribers at: anEventTrait put: #default ] ]

will check if the producer for the given eventTrait is the one we want to remove and if it's the case, it will set the value to the default one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants