This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Ezekiel Aquino
Posted Aug 13 - Read on Facebook

Hello everyone! Quick noob question: is it possible to make use of event emitters/listeners in Framer? Something like: Button is held -> emit('toggle', args) then anything within the prototype can listen to this event and react accordingly? :) thank you !

3 Comments

Joshua Tucker

Hey Ezekiel! Yes you can – all layers extend EventEmitter so you can create custom event listeners. You can also create your own EventEmitter inside Framer. I put together an example that shows how to do it in two different ways. One example shows how you would emit on all the layers with that listener. The second is creating an EventEmitter, setting up a handler, and then looping through a set of layers (doesn't require that they have event listeners). Of course in either example you can do whatever logic you want.

http://share.framerjs.com/pty77sx8j7en/

As for every layer in the prototype being able to listen in, the way I was able to achieve this is looping through all the layers inside Framer and emitting the event. If they had listeners for it, cool. If not, then it didn't emit. I'm not so sure this is the most performant way, but it's the only way I could see where all of layers could have the event emitted. cc Jordan Robert Dobson

Jordan Robert Dobson

I'm going to be tackling a similar problem today... I'll let you know what I find. :D

Jordan Robert Dobson

Wow. This is so great. So many areas you can dig into. Handing events with your second method streamlined my code setup tremendously. Now each class just worried about itself and just responds to events from anywhere using a shared event emitter between classes. :D

Read the entire post on Facebook