Comments (4)
pebble.js internally uses its own Emitter or event dispatcher implementation which calls all listeners or callbacks with three parameters, event
, eventType
, and listenerIndex
where listenerIndex
is the listener's position among all listeners currently registered to the same object's eventType
.
This is not documented because this is a feature specific to the underlying Emitter implementation that none of the classes that depend on it rely on. It may change before a stable release.
Thinking about it again, I may actually remove those other two parameters. eventType
might be removed because some events also have a subtype, and yet it's not being passed as a parameter. listenerIndex
is for cases where listener order is important for dynamic listeners, although receiving that information after registration isn't quite useful except possibly for debugging to figure out if something else is registered before the current handler executing. There should have probably been a fourth parameter totalListeners
.
The original reason for eventType
was in case the event object is missing the type
field. This is not possible now since Emitter sets the type
field automatically, unless a frozen object is emitted. As you've noticed, eventType
continues to be passed for dynamic listeners despite type
being automatically set.
Thanks for having me look into this again. If the eventType
is actually useful for you or anyone else, I can instead consider changing listenerIndex
into eventSubtype
instead of removing both parameters. And of course, the final Emitter behavior would then be documented.
from pebblejs.
For the app I'm currently working on, the eventType
is not important. I can't comment on whether or not it might be useful in the future though!
This issue probably would never impact anyone unless they have a similar coding style to me...
I have an event handler function that also takes an optional parameter that is only expected when the function is called directly. Reading the documentation, I expected parameter 2 to be undefined - but actually, it was populated, so my "optional" parameter had to be number 4!
I'm not normally a JavaScript developer (more Java & C actually), so I'm not used to having such flexible callback function definitions :-)
from pebblejs.
Ah, I see, I'm leaning towards removing them then as that sounds like a fairly common use case that I overlooked by only using anonymous functions most of the time.
In the mean time you could use an additional anonymous function Menu.on('select', function(e) { myFunction(e); })
. It seems wasteful, but with this arrangement, you could, for example, move logic that only performs if it was called by the event (if any) into this new function. Or at the very least, guard against this API change.
I have to admit this could be a breaking change, so it might be awhile for it to land.
from pebblejs.
With more JS experience under my belt, clearly the anonymous callback is the correct solution!
from pebblejs.
Related Issues (20)
- [Bug] Run time error when show UI.card() HOT 4
- [Bug] Error when building with the SDK 3.10 HOT 1
- [Feature Request] Disconnected message as a customisable image, like the startup screen
- [Bug] Card goes fullscreen when going back from Menu
- need a cloudpebble update HOT 3
- Bug in OGPebble 3.11.1 HOT 3
- Accel 'tap' event not very sensitive HOT 4
- Number conversion to string - Menus HOT 2
- App crashed when move from a Window to Menu HOT 17
- [Bug] Menu Screen Dotted Line HOT 3
- [Bug] Scrolling issue on Aplite HOT 6
- Circle.radius accessor is undefined HOT 1
- Modifications while Voice window is the top window cause a crash HOT 1
- Cloud Pebble Unable to Upload Images (PNG)
- Settings.config callback crashes when passed option containing encoded percent sign HOT 2
- Pebble.js compilation fails for Pebble 2 / Diorid HOT 2
- Application crash on pebble HOT 10
- Porting Pebble.js to Canvas (rocky.js)
- Wakeup not discarding itself or cancelling
- .
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 pebblejs.