-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added new rx events for debounce and proxy
- Loading branch information
Showing
7 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Jeli event manager | ||
* @param {*} element | ||
*/ | ||
export function CustomEventHandler(element) { | ||
var trigger = (event) => { this.trigger(event); }; | ||
this.element = element; | ||
this.registeredEvents = {}; | ||
this.register = function(type, callback) { | ||
var index = -1; | ||
if (this.element && this.registeredEvents) { | ||
if (!this.registeredEvents.hasOwnProperty(type)) { | ||
this.registeredEvents[type] = []; | ||
this.element.addEventListener(type, trigger, false); | ||
} | ||
index = this.registeredEvents[type].push(callback); | ||
/** | ||
* unregister | ||
*/ | ||
return () => this.registeredEvents[type].splice(index - 1, 1); | ||
} | ||
}; | ||
} | ||
|
||
CustomEventHandler.prototype.trigger = function(event) { | ||
var listeners = this.registeredEvents[event.type] || []; | ||
for(var i=0; i<listeners.length; i++){ | ||
listeners[i](event); | ||
} | ||
}; | ||
|
||
CustomEventHandler.prototype.destroy = function() { | ||
for (var type in this.registeredEvents) { | ||
this.registeredEvents[type].length = 0; | ||
delete this.registeredEvents[type]; | ||
this.element.removeEventListener(type, trigger, false); | ||
} | ||
this.element = null; | ||
this.registeredEvents = null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* | ||
* @param {*} event | ||
* @param {*} target | ||
* @returns | ||
*/ | ||
export function ProxyEvent(event, target) { | ||
var eventProps = ['pageX', 'pageY', 'screenX', 'screenY', 'x', 'y', 'clientX', 'clientY', 'type', 'width', 'height', 'offsetX', 'offsetY']; | ||
return eventProps.reduce((accum, name) => (accum[name] = event[name], accum), { | ||
target, | ||
preventDefault: event.preventDefault | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { debounce } from "./rx.utils"; | ||
|
||
export function EventDebounce(timer, immediate) { | ||
AbstractEventRx.call(this); | ||
this._callback = debounce(value => { | ||
_eventRxTrigger(this, value); | ||
}, timer, immediate); | ||
} | ||
|
||
EventDebounce.prototype = Object.create(AbstractEventRx.prototype); | ||
EventDebounce.prototype.constructor = AbstractEventRx; | ||
EventDebounce.prototype.next = function(args) { | ||
this._callback(args); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export function RouteErrorEvent(path){ | ||
this.url = path; | ||
this.message = 'unable to resolve route'; | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
/** | ||
* | ||
* @param {*} route | ||
* @param {*} path | ||
* @param {*} redirectMethod | ||
*/ | ||
export function RouteInterceptorInstance(route, path, currentRoute, redirectMethod) { | ||
this.name = route.name; | ||
this.path = path; | ||
this.locals = {}; | ||
this.currentRoute = currentRoute; | ||
this.originalUrl = route.url; | ||
this.data = route.data; | ||
this.redirect = redirectMethod; | ||
Object.defineProperty(this, 'params', { | ||
get: () => route.route.params | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* | ||
* @param {*} path | ||
* @param {*} route | ||
* @param {*} previousRoute | ||
* @param {*} previousPath | ||
*/ | ||
export function RouteEvent(path, route, previousRoute, previousPath){ | ||
this.path = path; | ||
this.name = route.name; | ||
this.params = route.route.params; | ||
this.data = route.data; | ||
if (previousPath) { | ||
this.previous = { | ||
path: previousPath, | ||
name: previousRoute.name, | ||
params: previousRoute.route.params | ||
}; | ||
} | ||
} |