mirror of
https://github.com/flynx/types.js.git
synced 2025-12-19 18:01:39 +00:00
bugfix...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
aadb1a7c07
commit
d11202e51b
18
event.js
18
event.js
@ -131,6 +131,8 @@ function(name, func, options={}){
|
||||
}) }
|
||||
|
||||
|
||||
module.TRIGGER = {doc: 'force event method to trigger'}
|
||||
|
||||
// Extends Eventfull(..) adding ability to bind events via the
|
||||
// resulting method directly by passing it a function...
|
||||
//
|
||||
@ -157,6 +159,16 @@ function(name, func, options={}){
|
||||
// func(handle, ...args)
|
||||
//
|
||||
//
|
||||
// Special case:
|
||||
//
|
||||
// Force trigger event...
|
||||
// method(TRIGGER, ...args)
|
||||
// -> this
|
||||
//
|
||||
// This will pass args to the event action regardless whether the first
|
||||
// arg is a function or not...
|
||||
//
|
||||
//
|
||||
var Event =
|
||||
module.Event =
|
||||
function(name, func, options={}){
|
||||
@ -169,12 +181,14 @@ function(name, func, options={}){
|
||||
method = Eventfull(name,
|
||||
function(handle, ...args){
|
||||
// add handler...
|
||||
// XXX handle handler tags...
|
||||
if(typeof(args[0]) == 'function'){
|
||||
method.__event_handler_add__(this, args[0])
|
||||
|
||||
// call the action...
|
||||
} else {
|
||||
// special case: force trigger -> remove TRIGGER from args...
|
||||
args[0] === module.TRIGGER
|
||||
&& args.shift()
|
||||
func
|
||||
&& func.call(this, handle, ...args) }
|
||||
|
||||
@ -240,7 +254,7 @@ module.EventHandlerMixin = {
|
||||
trigger: function(evt, ...args){
|
||||
// local handler...
|
||||
evt in this
|
||||
&& this[evt](...args)
|
||||
&& this[evt](module.TRIGGER, ...args)
|
||||
// global events...
|
||||
this.__event_handlers__
|
||||
&& (this.__event_handlers__[evt] || [])
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ig-types",
|
||||
"version": "3.7.1",
|
||||
"version": "3.7.2",
|
||||
"description": "Generic JavaScript types and type extensions...",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
||||
@ -234,6 +234,7 @@ module.Queue = object.Constructor('Queue', Array, {
|
||||
&& running.length < (this.pool_size || Infinity) ){
|
||||
|
||||
var task = this.shift()
|
||||
// XXX BUG this executes the task for some reson...
|
||||
this.trigger('taskStarting', task)
|
||||
|
||||
// run...
|
||||
@ -254,11 +255,13 @@ module.Queue = object.Constructor('Queue', Array, {
|
||||
.filter(function(e){ return e !== res }))
|
||||
// finishup...
|
||||
that
|
||||
// XXX BUG this executes the task for some reson...
|
||||
.trigger('taskCompleted', task, res)
|
||||
._run() })
|
||||
|
||||
// completed sync task...
|
||||
} else {
|
||||
// XXX BUG this executes the task for some reson...
|
||||
this.trigger('taskCompleted', task, res) } }
|
||||
|
||||
// empty queue -> pole or stop...
|
||||
|
||||
56
test.js
56
test.js
@ -472,6 +472,11 @@ Events.cases({
|
||||
.event()
|
||||
.event()
|
||||
assert(called['event-one-time-handler'] == 1, '.one("event", ..) handler cleared.')
|
||||
delete called['event-one-time-handler']
|
||||
|
||||
// special case...
|
||||
obj.trigger('event', function(){ called['trigger-function-called'] = true })
|
||||
assert(called['trigger-function-called'] === undefined, '.trigger(..) should not call it\'s args')
|
||||
|
||||
// XXX test passing args...
|
||||
|
||||
@ -483,6 +488,57 @@ Events.cases({
|
||||
})
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// events...
|
||||
|
||||
var Runner = test.TestSet()
|
||||
test.Case('Runner', Runner)
|
||||
|
||||
// XXX test aborting handlers...
|
||||
Runner.cases({
|
||||
base: function(assert){
|
||||
//var q = assert(runner.Queue({auto_stop: true}), 'Queue()')
|
||||
var q = assert(runner.Queue(), 'Queue()')
|
||||
|
||||
// empty states...
|
||||
assert(q.state == 'stopped', '.state: stopped')
|
||||
|
||||
q.start()
|
||||
|
||||
assert(q.state == 'running', '.state: running')
|
||||
|
||||
q.start()
|
||||
|
||||
assert(q.state == 'running', '.state: running')
|
||||
|
||||
q.stop()
|
||||
|
||||
assert(q.state == 'stopped', '.state: stopped')
|
||||
|
||||
var tasks_run = []
|
||||
var a = function(){ tasks_run.push('a') }
|
||||
var b = function(){ tasks_run.push('b') }
|
||||
var c = function(){ tasks_run.push('c') }
|
||||
|
||||
q.push(a)
|
||||
q.push(b)
|
||||
q.push(c)
|
||||
|
||||
assert(q.length == 3, '.length is 3')
|
||||
|
||||
// for some reason this runs the tasks above multiple times...
|
||||
q.start()
|
||||
|
||||
assert.array(tasks_run, ['a', 'b', 'c'], 'all tasks run')
|
||||
|
||||
|
||||
|
||||
|
||||
//console.log('\n>>>', q.state)
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
typeof(__filename) != 'undefined'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user