We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Use this.$sse.once(), it will be triggered continuously instead of only once.
sorry,I won't use jest to write this test (-。-!)
I made the following modifications to test the feasibility:
path: src/sse-client.js
`once(event, handler) {
//old - this.on(event, (e) => { - this.off(event, handler); - handler(e); - }); //new change-1: start const once = e => { handler(e); this.off(event, handler); }; once.initialhandle = handler;// this.on(event, once); //change-1: end return this;
}`
`off(event, handler) { if (!this._handlers[event]) { // no handlers registered for event return this; }
//old const idx = this._handlers[event].indexOf(handler); if (idx === -1) { // handler not registered for event return this; } // remove handler from event this._handlers[event].splice(idx, 1); //new change-2 start // if handler is null ,remove all handler from event if (!handler) { delete this._handlers[event]; return this; } //initialhandle 标识出 once 的handler this._handlers[event] = this._handlers[event].filter( item => item !== handler && item.initialhandle != handler ); //change-2 end if (this._handlers[event].length === 0) { // remove listener since no handlers exist this._source.removeEventListener(event, this._listeners[event]); delete this._handlers[event]; delete this._listeners[event]; } return this; }
`
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Use this.$sse.once(), it will be triggered continuously instead of only once.
sorry,I won't use jest to write this test (-。-!)
I made the following modifications to test the feasibility:
path: src/sse-client.js
api: once
`once(event, handler) {
}`
api: off
`off(event, handler) {
if (!this._handlers[event]) {
// no handlers registered for event
return this;
}
`
The text was updated successfully, but these errors were encountered: