tunnckocorelabs / dush Goto Github PK
View Code? Open in Web Editor NEW:clap: Microscopic & functional event emitter in ~350 bytes, extensible through plugins.
Home Page: https://unpkg.com/dush/dist/dush.umd.js
License: MIT License
:clap: Microscopic & functional event emitter in ~350 bytes, extensible through plugins.
Home Page: https://unpkg.com/dush/dist/dush.umd.js
License: MIT License
Here's the Weekly Digest for tunnckoCoreLabs/dush:
Last week, no issues were created.
Last week, no pull requests were created, updated or merged.
Last week there were no commits.
Last week there were no contributors.
Last week there were no stargazers.
Last week there were no releases.
That's all for last week, please ๐ Watch and โญ Star the repository tunnckoCoreLabs/dush to receive next weekly updates. ๐
You can also view all Weekly Digests by clicking here.
Your Weekly Digest bot. ๐
Since .all
is pretty common. Maybe ._all
or why not ._allEvents
- with or without dash.
Here's the Weekly Digest for tunnckoCoreLabs/dush:
Last week, no issues were created.
Last week, no pull requests were created, updated or merged.
Last week there were no commits.
Last week there were no contributors.
Last week there were no stargazers.
Last week there were no releases.
That's all for last week, please ๐ Watch and โญ Star the repository tunnckoCoreLabs/dush to receive next weekly updates. ๐
You can also view all Weekly Digests by clicking here.
Your Weekly Digest bot. ๐
use: function use(plugin, options) {
var ret = plugin(app, options)
return Object.assign(app, ret)
},
Which will be used to extend the returned object. Inheritance.
For example
var app = dush({
foo: 'bar'
})
console.log(app.foo) // => 'bar'
console.log(app.on) // => function
I haven't investigated to precisely determine the mechanism of the bug, but the behavior i saw was that binding the same handler to the same event with once multiple times would remove the wrong handler after firing.
so for example, you have an object which provides a token: myObject.getToken(), but my object is instantiated by an asynchronous process, you might write code like:
let tokenPromise = ()=>{
if(myObject) {
return new Promise((resolve) => {
resolve(myObject.getToken())
})
}
return new Promise((resolve)=>{
emitter.once('MY_OBJECT_CREATED', ()=>{
resolve(myObject.getToken())
})
})
}
multiple calls to tokenPromise results in the wrong handlers being unbound by once, i believe to confusion around the value of 'fn' within the once() method.
this seems to resolve the issue:
once: function once (name, handler) {
function fn (a, b, c) {
app.off(name, this);
handler(a, b, c);
}
return app.on(name, fn.bind(fn))
}
const emitter = dush()
const handler1 = () => { console.log('a') }
const handler2 = () => { console.log('a') }
emitter.on('a', handler1)
emitter.on('a', handler2)
emitter.off('a', handler1)
handler2 should not be removed
handler2 is removed because the lib uses fn.toString() to identify a function and source code of both functions looks the same
Here's the Weekly Digest for tunnckoCoreLabs/dush:
Last week, no issues were created.
Last week, no pull requests were created, updated or merged.
Last week there were no commits.
Last week there were no contributors.
Last week there were no stargazers.
Last week there were no releases.
That's all for last week, please ๐ Watch and โญ Star the repository tunnckoCoreLabs/dush to receive next weekly updates. ๐
You can also view all Weekly Digests by clicking here.
Your Weekly Digest bot. ๐
In the README.md file, all the handlers are described as strings , when they are functions indeed.
Here's the Weekly Digest for tunnckoCoreLabs/dush:
Last week, no issues were created.
Last week, no pull requests were created, updated or merged.
Last week there were no commits.
Last week there were no contributors.
Last week there were no stargazers.
Last week there were no releases.
That's all for last week, please ๐ Watch and โญ Star the repository tunnckoCoreLabs/dush to receive next weekly updates. ๐
You can also view all Weekly Digests by clicking here.
Your Weekly Digest bot. ๐
But we support any number of any type of value
to be emitted.
Because it will trigger listeners twice. See this reddit thread comment.
const emitter = dush()
emitter.on('*', (name, a, b, c) => {
console.log('args', name, a, b, c)
// => args foo 1 2 3
// => args 4 5 6 undefined
// => args * 4 5 6
})
emitter.emit('foo', 1, 2, 3)
emitter.emit('*', 4, 5, 6)
Reproduction code: https://jsfiddle.net/Lfozrhdw/
The issue is in line https://github.com/tunnckoCore/dush/blob/master/src/index.js#L146
Should be fn.__sourceString = fn.toString()
Here's the Weekly Digest for tunnckoCoreLabs/dush:
Last week, no issues were created.
Last week, no pull requests were created, updated or merged.
Last week there were no commits.
Last week there were no contributors.
Last week there were no stargazers.
Last week there were no releases.
That's all for last week, please ๐ Watch and โญ Star the repository tunnckoCoreLabs/dush to receive next weekly updates. ๐
You can also view all Weekly Digests by clicking here.
Your Weekly Digest bot. ๐
This doesn't seem to work as expected:
const emitter = dush()
const hello = () => console.log("You shouldn't see this.")
emitter.once('test', hello)
emitter.off('test', hello)
emitter.emit('test')
Like that
const dush = () => {
// ... code
}
const app = dush()
app.dush = dush
export default app
so we can just
const { on, off, once, emit, use } = require('dush')
or get the singleton
const { dush } = require('dush')
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.