Ejemplo n.º 1
0
VWO.prototype.initialize = function() {
  var self = this;
  if (this.options.replay) {
    tick(function() {
      self.replay();
    });
  }
  if (this.options.listen) {
    tick(function() {
      self.roots();
    });
  }
  this.ready();
};
Ejemplo n.º 2
0
 trakio.once('load', function () {
   tick(function () {
     window.trak.io.distinct_id = sinon.stub();
     window.trak.io.alias = sinon.spy();
     done();
   });
 });
 yandex.load(function (err) {
   if (err) return done(err);
   tick(function () {
     assert(window['yaCounter' + yandex.options.counterId]);
     done();
   });
 });
Ejemplo n.º 4
0
    it('should call ready and load library', function (done) {
      var spy  = sinon.spy()
        , push = Array.prototype.push;

      expect(window._errs).to.be(undefined);

      analytics.ready(spy);
      analytics.initialize({ 'Errorception' : test['Errorception'] });

      // Errorception sets up a queue, so it's ready immediately.
      expect(window._errs).not.to.be(undefined);
      expect(window._errs.push).to.equal(push);

      tick(function () {
        expect(spy.called).to.be(true);
      });

      // When the library loads, it will overwrite the push method.
      var interval = setInterval(function () {
        if (window._errs.push === push) return;
        expect(window._errs.push).not.to.equal(push);
        clearInterval(interval);
        done();
      }, 20);
    });
Ejemplo n.º 5
0
				fn = function (x, y, cb) {
					nextTick(function () {
						++i;
						cb(e);
					});
					return u;
				};
Ejemplo n.º 6
0
function asyncDone(fn, cb) {
  var sub = new Subject();

  cb = once(cb);

  var d = domain.create();
  d.once('error', onError);
  var domainBoundFn = d.bind(fn);

  function done(_, res) {
    d.removeListener('error', onError);
    d.exit();
    sub.next(res);
    sub.complete();
    return cb.apply(null, arguments);
  }

  function onSuccess(result) {
    return done(null, result);
  }

  function onError(error) {
    return done(error);
  }

  function asyncRunner() {
    var result = domainBoundFn(done);

    function onNext(state) {
      onNext.state = state;
      sub.next(state);
    }

    function onCompleted() {
      return onSuccess(onNext.state);
    }

    if (result && typeof result.on === 'function') {
      // Assume node stream
      d.add(result);
      eos(exhaust(result), eosConfig, done);
      return;
    }

    if (result && typeof result.subscribe === 'function') {
      // Assume RxJS observable
      result.subscribe(onNext, onError, onCompleted);
      return;
    }

    if (result && typeof result.then === 'function') {
      // Assume promise
      result.then(onSuccess, onError);
      return;
    }
  }

  tick(asyncRunner);
  return sub;
}
Ejemplo n.º 7
0
	conf.on('get', function (id) {
		var cb, context, args;
		if (!currentCallback) return;

		// Unresolved
		if (waiting[id]) {
			if (typeof waiting[id] === 'function') waiting[id] = [waiting[id], currentCallback];
			else waiting[id].push(currentCallback);
			currentCallback = null;
			return;
		}

		// Resolved, assure next tick invocation
		cb = currentCallback;
		context = currentContext;
		args = currentArgs;
		currentCallback = currentContext = currentArgs = null;
		nextTick(function () {
			var data;
			if (hasOwnProperty.call(cache, id)) {
				data = cache[id];
				conf.emit('getasync', id, args, context);
				apply.call(cb, data.context, data.args);
			} else {
				// Purged in a meantime, we shouldn't rely on cached value, recall
				currentCallback = cb;
				currentContext = context;
				currentArgs = args;
				base.apply(context, args);
			}
		});
	});
Ejemplo n.º 8
0
MutableFocusHook.prototype.hook = function hook(node, property) {
    nextTick(function onTick() {
        if (document.activeElement !== node) {
            node.focus();
        }
    });
};
Ejemplo n.º 9
0
			asyncArgs.push(value = function self(err) {
				var i, cb, waiting, res;
				if (self.id == null) {
					// Shouldn't happen, means async callback was called sync way
					nextTick(apply.bind(self, this, arguments));
					return;
				}
				waiting = cache[self.id];
				if (conf.cache.hasOwnProperty(self.id)) {
					if (err) {
						delete cache[self.id];
						conf.clear(self.id);
					} else {
						arguments.context = this;
						cache[self.id] = arguments;
						conf.emit('initasync', self.id, waiting.length);
					}
				} else {
					delete cache[self.id];
				}
				for (i = 0; (cb = waiting[i]); ++i) {
					res = apply.call(cb, this, arguments);
				}
				return res;
			});
Ejemplo n.º 10
0
renameElement.prototype.init = function(){
  var element = document.createElement('span')
  this.element = element
  element.context = this
  element.dataset.extname = getExtName(this.fileName)
  element.textContent = getBaseName(this.fileName, element.dataset.extname)
  element.onkeydown = function(e){
    if (event.keyCode === 13){
      element.context.saveRename()
      return false
    } else if (event.keyCode === 27){
      element.context.cancelRename()
      return false
    }
  }
  element.onblur = function handleRenameBlur(e){
    nextTick(function(){
      if (element.parentNode && element.context){
        // only save if still active!
        element.context.saveRename()
      }
    })
  }
  element.contentEditable = true
  nextTick(function(){
    selectInside(element)
  })
  return element
}
Ejemplo n.º 11
0
		cb = function self(err) {
			var cb, args, id = self.id;
			if (id == null) {
				// Shouldn't happen, means async callback was called sync way
				nextTick(apply.bind(self, this, arguments));
				return;
			}
			delete self.id;
			cb = waiting[id];
			delete waiting[id];
			if (!cb) {
				// Already processed,
				// outcome of race condition: asyncFn(1, cb), asyncFn.clear(), asyncFn(1, cb)
				return;
			}
			args = aFrom(arguments);
			if (conf.has(id)) {
				if (err) {
					conf.delete(id);
				} else {
					cache[id] = { context: this, args: args };
					conf.emit('setasync', id, (typeof cb === 'function') ? 1 : cb.length);
				}
			}
			if (typeof cb === 'function') {
				result = apply.call(cb, this, args);
			} else {
				cb.forEach(function (cb) { result = apply.call(cb, this, args); }, this);
			}
			return result;
		};
Ejemplo n.º 12
0
				nextTick(function () {
					a(i, 2, "Again Called #2");

					a(mfn.deleteRef(3, 7), false, "Delete ref #1");
					a(mfn.deleteRef(3, 7), false, "Delete ref #2");
					a(mfn.deleteRef(3, 7), false, "Delete ref #3");
					a(mfn.deleteRef(3, 7), true, "Delete ref Final");

					a(
						mfn(3, 7, function (err, res) {
							a.deep([err, res], [null, 10], "Again: Result");
						}),
						u,
						"Again: Initial"
					);
					a(
						mfn(5, 8, function (err, res) {
							a.deep([err, res], [null, 13], "Again B: Result");
						}),
						u,
						"Again B: Initial"
					);

					nextTick(function () {
						a(i, 3, "Call After delete");
						d();
					});
				});
Ejemplo n.º 13
0
				fn = function (x, y, cb) {
					nextTick(function () {
						++i;
						cb(null, x + y);
					});
					return u;
				};
Ejemplo n.º 14
0
  it("should remove jobs that haven't run yet", function(done){
    var q = new Queue;
    var calls = [];

    q.push(function(fn){
      calls.push('one');
      setTimeout(function(){
        calls.push('two');
        fn();
      }, 100);
    });

    q.push(function(fn){
      calls.push('flushed');
      fn();
    });

    nextTick(function(){
      q.flush();

      q.push(function(fn){
        calls.push('three');
        setTimeout(function(){
          fn();
          calls.should.eql(['one', 'two', 'three']);
          done();
        }, 100);
      });
    });

  })
Ejemplo n.º 15
0
				nextTick(function () {
					a(i, 2, "Init Called");
					a(invoked, 5, "Cb Called");

					a(mfn(3, 7, function (err, res) {
						++invoked;
						a.deep([err, res], [null, 10], "Again: Result");
					}), u, "Again: Initial");
					a(mfn(5, 8, function (err, res) {
						++invoked;
						a.deep([err, res], [null, 13], "Again B: Result");
					}), u, "Again B: Initial");

					nextTick(function () {
						a(i, 2, "Init Called #2");
						a(invoked, 7, "Cb Called #2");

						mfn.clear(3, 7);

						a(mfn(3, 7, function (err, res) {
							++invoked;
							a.deep([err, res], [null, 10], "Again: Result");
						}), u, "Again: Initial");
						a(mfn(5, 8, function (err, res) {
							++invoked;
							a.deep([err, res], [null, 13], "Again B: Result");
						}), u, "Again B: Initial");

						nextTick(function () {
							a(i, 3, "Init  After clear");
							a(invoked, 9, "Cb After clear");
							d();
						});
					});
				});
Ejemplo n.º 16
0
/**
 * Show the view. This waits until after any transitions
 * are finished. It also removed the hide class on the next
 * tick so that the transition actually paints.
 */
function show(fn){
  var self = this;

  if(this.hidden == null) {
    this.hidden = this.el.classList.contains('hidden');
  }

  if(this.hidden === false || this.animating) return;

  this.hidden = false;
  this.animating = true;

  this.emit('showing');

  after(self.el, function(){
    self.animating = false;
    self.emit('show');
    if(fn) fn();
  });

  this.el.offsetHeight;

  nextTick(function(){
    self.el.classList.remove('hidden');
  });

  return this;
}
Ejemplo n.º 17
0
    hook: function hook(node) {

      nextTick(function() {

        if (!document.body.contains(node)) {
          return;
        }

        var scroller = scrollTabs.get(node);

        if (!scroller) {
          debug('init');

          scroller = scrollTabs(node, options);

          scroller.__windowResize = function() {
            debug('window-resize');

            raf(function() {
              debug('update');
              scroller.update();
            });
          };

          scroller.on('scroll', onScroll);

          // react on window resize
          window.addEventListener('resize', scroller.__windowResize, false);
        }

        debug('update');
        scroller.update();
      });
    },
Ejemplo n.º 18
0
				nextTick(function () {
					a(i, 2, "Called #2");

					a(mfn(3, 7, function (err, res) {
						a.deep([err, res], [null, 10], "Again: Result");
					}), u, "Again: Initial");
					a(mfn(5, 8, function (err, res) {
						a.deep([err, res], [null, 13], "Again B: Result");
					}), u, "Again B: Initial");

					nextTick(function () {
						a(i, 2, "Again Called #2");

						mfn.clear(3, 7);

						a(mfn(3, 7, function (err, res) {
							a.deep([err, res], [null, 10], "Again: Result");
						}), u, "Again: Initial");
						a(mfn(5, 8, function (err, res) {
							a.deep([err, res], [null, 13], "Again B: Result");
						}), u, "Again B: Initial");

						nextTick(function () {
							a(i, 3, "Call After clear");
							d();
						});
					});
				});
Ejemplo n.º 19
0
 klaviyo.load(function (err) {
   if (err) return done(err);
   tick(function () {
     assert(klaviyo.loaded());
     done();
   });
 });
 it('should call #replay by default', function (done) {
   optimizely.replay = sinon.spy();
   optimizely.initialize();
   tick(function () {
     assert(optimizely.replay.called);
     done();
   });
 });
Ejemplo n.º 21
0
VWO.prototype.replay = function(){
  var analytics = this.analytics;
  tick(function(){
    experiments(function(err, traits){
      if (traits) analytics.identify(traits);
    });
  });
};
Ejemplo n.º 22
0
 element.onblur = function handleRenameBlur (e) {
   nextTick(function () {
     if (element.parentNode) {
       // only save if still active!
       save()
     }
   })
 }
Ejemplo n.º 23
0
			"Success": function (a, d) {
				var mfn, fn, u = {}, i = 0;
				fn = function (x, y, cb) {
					nextTick(function () {
						++i;
						cb(null, x + y);
					});
					return u;
				};

				mfn = memoize(fn, { async: true, primitive: true });

				a(mfn(3, 7, function (err, res) {
					a.deep([err, res], [null, 10], "Result #1");
				}), u, "Initial");
				a(mfn(3, 7, function (err, res) {
					a.deep([err, res], [null, 10], "Result #2");
				}), u, "Initial #2");
				a(mfn(5, 8, function (err, res) {
					a.deep([err, res], [null, 13], "Result B #1");
				}), u, "Initial #2");
				a(mfn(3, 7, function (err, res) {
					a.deep([err, res], [null, 10], "Result #3");
				}), u, "Initial #2");
				a(mfn(5, 8, function (err, res) {
					a.deep([err, res], [null, 13], "Result B #2");
				}), u, "Initial #3");

				nextTick(function () {
					a(i, 2, "Called #2");

					a(mfn(3, 7, function (err, res) {
						a.deep([err, res], [null, 10], "Again: Result");
					}), u, "Again: Initial");
					a(mfn(5, 8, function (err, res) {
						a.deep([err, res], [null, 13], "Again B: Result");
					}), u, "Again B: Initial");

					nextTick(function () {
						a(i, 2, "Again Called #2");

						mfn.clear(3, 7);

						a(mfn(3, 7, function (err, res) {
							a.deep([err, res], [null, 10], "Again: Result");
						}), u, "Again: Initial");
						a(mfn(5, 8, function (err, res) {
							a.deep([err, res], [null, 13], "Again B: Result");
						}), u, "Again B: Initial");

						nextTick(function () {
							a(i, 3, "Call After clear");
							d();
						});
					});
				});
			},
 it('should not call #replay if variations are disabled', function (done) {
   optimizely.replay = sinon.spy();
   optimizely.options.variations = false;
   optimizely.initialize();
   tick(function () {
     assert(!optimizely.replay.called);
     done();
   });
 });
Ejemplo n.º 25
0
 it('should load an href on click', function (done) {
   link.href = '#test';
   analytics.trackLink(link);
   trigger(link, 'click');
   tick(function () {
     assert(window.location.hash == '#test');
     done();
   });
 });
Ejemplo n.º 26
0
 it('should callback after a timeout', function (done) {
   var spy = sinon.spy();
   analytics._callback(spy);
   assert(!spy.called);
   tick(function () {
     assert(spy.called);
     done();
   });
 });
Ejemplo n.º 27
0
module.exports = function(canvas) {
  var noise = new Noise({
    canvas: canvas
  })
  nextTick(function() {
    noise._auto && noise.generate()
  })
  return noise
}
Ejemplo n.º 28
0
 analytics.ready(function () {
   var spy = sinon.spy();
   analytics.ready(spy);
   assert(!spy.called);
   tick(function () {
     assert(spy.called);
     done();
   });
 });
	return new Constructor(function (resolve) {
		if (isValue(timeout)) {
			setTimeout(function () {
				resolve();
			}, timeout);
		} else {
			nextTick(resolve);
		}
	});
Ejemplo n.º 30
0
 it('should not load an href for a link with a blank target', function (done) {
   link.href = '/test/server/mock.html';
   link.target = '_blank';
   analytics.trackLink(link);
   trigger(link, 'click');
   tick(function () {
     assert(window.location.hash != '#test');
     done();
   });
 });