Giter VIP home page Giter VIP logo

zone.js's Introduction

Zone.js

The zone.js repo has been moved to angular mono repo here, This repo has been archived. Please create issue in angular repo. Thanks!

zone.js's People

Contributors

alexeagle avatar alxhub avatar brooooooklyn avatar btford avatar caitp avatar chuckjaz avatar hmdhk avatar igorminar avatar jahtalab avatar jeffbcross avatar jialipassion avatar jteplitz avatar juliemr avatar justindujardin avatar kwintenp avatar manishbansal8843 avatar marclaval avatar matthewjh avatar mhevery avatar mtsmfm avatar patrickjs avatar platosha avatar poxrud avatar qiyigg avatar rkirov avatar robwormald avatar sjelin avatar unframework avatar vicb avatar vikerman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zone.js's Issues

setInterval RangeError: Maximum call stack

Using the preview here: https://github.com/angular/quickstart

Adding setInterval anywhere throws an error

es6-shim.js:29889 Uncaught RangeError: Maximum call stack size exceeded
es6-shim.js:29889 run
es6-shim.js:29866 zoneBoundFn
es6-shim.js:29940 fnNames.map.forEach.zone.(anonymous function).arguments.(anonymous function)
es6-shim.js:29873 (anonymous function)
es6-shim.js:29889 runes6-shim.js:29866 zoneBoundFn
es6-shim.js:29940 fnNames.map.forEach.zone.(anonymous function).arguments.(anonymous function)
es6-shim.js:29873 (anonymous function)
es6-shim.js:29889 run
es6-shim.js:29866 zoneBoundFn

bug: Angular 1.x App with Zone.js

I am trying to experimenting Zone.js with Angularjs. I have problem using Zone.longStackTraceZone in my controllers.

Here is the flow of my test app.

function startApp() {
  angular.bootstrap( document, ['app']);
}
....

document ready

var myZone = zone.fork(Zone.longStackTraceZone).run (  startApp)

I also have a "Bind Error / Cause Error" example on my page, and I was able to capture the long stack trace.

However in my angular controller, I purposely throw a new Error on a ngclick, I can just see the normal angular exception in my console, any ideas?

bug: `websocket.addEventListener` not properly wrapped

Even though #9 shows that websockets is working it does not seem to be the case.

For example when messages get received from a websocket, the afterTask doesn't run:

function run() {
  var sock = new WebSocket('ws://' + location.host + '/changes/websocket');
  sock.addEventListener('open', function (evt) {
    sock.send(JSON.stringify({ hello: 'world' }));
  });

  sock.addEventListener('message', function (evt) {
    var msg = JSON.parse(evt.data);
    console.log('message', msg);
  });
}

zone.fork(watchZone()).run(run);
function watchZone() {
  return {
    afterTask: function () {
      console.log('after');
    }
  };
}

EventTarget assumed to be in window

It is of my understanding of the spec that there's no implication that EventTarget will be available on window. While major browsers appear to expose it I imagine there are DOM implementations that do not (jsdom being one for sure - it causes an error).
So I propose patching methods in Node.prototype instead of EventTarget.prototype.

Can we implement a `process.on('exit')` polyfill

The semantics of process.on('exit', fn) in node is you can run a function before exiting.

The way node knows your about to exit is that your current entry point has run to completion and there is nothing scheduled on the event loop.

In theory zone.js might be able to do something similar, intercept every single callback before it goes on the event loop, increment a counter and decrement it when the event loop calls your callback.

This would allow us to know when there are no tasks left of the event loop and emit some kind of "exit" event.

We also need to make sure there are no open event listeners on any handles like window or document.body.

VM Turns are not properly detected, could impact perf

This is how to "run some function at the end of each VM turn" from the README

zone.fork({
  afterTask: function () {
    // do some cleanup
  }
}).run(function () {
  // do stuff
});

But consider the following code:

function schedule() {
  setTimeout(function() { console.log('setTimeout')}, 0);
  Promise.resolve('promise')
    .then(function(_) { console.log(_); return 'then'; })
    .then(function(_) { console.log(_); })
  ;
}

zone
  .fork({
    afterTask: function () { console.log('vm turn end'); }
  })
  .run(schedule);

If VM turn were properly detected, the output shoud be

vm turn end
// microtask queue
promise
then
// macrotask queue
setTimeout
vm turn end

but the actual output is

vm turn end
promise
vm turn end
then
vm turn end
setTimeout
vm turn end

I believe this means that the change detection would run 3x more than required in Angular2 on such a code.

/cc @vsavkin @btford

How to call original function from the alternative one?

I tried to override setTimeout and faced a problem.

    zone.fork({
      setTimeout: function(fn, time) {
        // this causes infinite loop
        setTimeout(function() {
          console.log('setTimeout start');
          fn()
          console.log('setTimeout end');
        }, time);
      }
    }).run(...);

Where is the original setTimeout? (I think parent's setTimeout is better.)
Or is there another way to do something like this?

[Research] zone + microtask

The first implementation of zone + microtask (see #82) works as follow:

  • We use a monkey patch of Promise (es6-promise) so that we know when a microtask is scheduled,
  • At the end of a macrotask, we execute pending microtasks (there is a check at then end of run())

That means than zone.js also acts as a scheduler for microtasks.

An other option would be to let JavaScript schedule microtasks. The JS implementation would become more similar to Dart zones.

onerror test failure

If you fit the currently failing onerror test, it passes.
This may be due to some zone leakage (zones not being cleaned up after a VM turn).

via @IgorMinar

Root zone should not wrap callbacks

Currently the root zone wraps everything into callbacks and spawning new zones

The root zone should be inert, and not fork new zones. Only once you install some behavior via the first call to fork, then we should start wrapping calls into new zones.

Via @IgorMinar

browserify tests fail on Safari due to duplicate Zone.init()

in the browserify tests we import Zone which calls init() again on a window that has been already patched by previous tests, this causes failures due to double patching.

Ideally we should detect that Zone has already patched the context and not patch it again which would also help in scenarios where someone includes zone.js twice in the same context.

TypeError: Cannot read property '_bound' of undefined

It looks like Safari isn't able to patch at all with upstream fixes

Been working hard on fixing all of the syntax errors and getting the transpiler to produce valid code, and it looks like it's just about there --- however, there seem to be some issues with (largely) Zone.js at this point. @btford you're probably better at figuring out where these issues are coming from? But to me it looks like Safari isn't able to be patched at all

screen shot 2015-03-02 at 12 36 02 pm

Unable to run tests

I forked and clone the repo, ran npm install then npm test and I got these errors

~/zone.js(master %=) $ npm test

> [email protected] test /Users/daryl/zone.js
> karma start --browsers Firefox --single-run

INFO [karma]: Karma v0.10.10 server started at http://localhost:9876/
INFO [launcher]: Starting browser Firefox
INFO [Firefox 29.0.0 (Mac OS X 10.9)]: Connected on socket zoScuoi9PoEvZ3zxEgLj
DUMP: undefined
LOG: 'WARNING: HTML Imports test (missing this API)'
LOG: 'WARNING: skipping WebKitMutationObserver test (missing this API)'
Firefox 29.0.0 (Mac OS X 10.9) document.registerElement should work with createdCallback FAILED
    Expected false to be true.
    @/Users/daryl/zone.js/test/patch/registerElement.spec.js:55

Firefox 29.0.0 (Mac OS X 10.9) document.registerElement should work with attachedCallback FAILED
    timeout: timed out after 100 msec waiting for attachedCallback to fire
Firefox 29.0.0 (Mac OS X 10.9) document.registerElement should work with detachedCallback FAILED
    timeout: timed out after 100 msec waiting for detachedCallback to fire
Firefox 29.0.0 (Mac OS X 10.9) document.registerElement should work with attributeChanged FAILED
    timeout: timed out after 100 msec waiting for attributeChanged to fire
Firefox 29.0.0 (Mac OS X 10.9) document.registerElement should work with prototypes that have non-writable, non-configurable descriptors FAILED
    Expected false to be true.
    @/Users/daryl/zone.js/test/patch/registerElement.spec.js:129

Firefox 29.0.0 (Mac OS X 10.9) document.registerElement should work with prototypes that have non-writable, non-configurable descriptors FAILED
    Expected false to be true.
    @/Users/daryl/zone.js/test/patch/registerElement.spec.js:155

LOG: 'WARNING: skipping requestAnimationFrame test (not firing rAF)'
LOG: 'WARNING: skipping webkitRequestAnimationFrame test (missing this API)'
Firefox 29.0.0 (Mac OS X 10.9): Executed 43 of 43 (6 FAILED) (0.665 secs / 0.495 secs)
npm ERR! Test failed.  See above for more details.
npm ERR! not ok code 0

I wouldn't be surprised if I'm forgetting something basic. Is there a contributor's guide somewhere?

NPE when calling zone.getLongStackTrace();

When calling zone.getLongStackTrace() from console (during debug). The method throws an NPE because exception is not specified. It would be useful to make the exception optional so that it would be easy to query the current location.

The issue is in long-stack-trace-zone.js#L50

A simple check to ignore null exception should suffice.

What is the state of the project?

Hi,

There are no new commits to this repository for a while. Does it mean that the project is not gonna be developed later. Are there any future plans?

Thank you.

WebSocket patching fails on Safari 7.0 for onopen, onmessage, onclose, onerror properties

When zone detects that we can't patch prototype descriptors, we call patchWebSocketProperties which tries to patch onmessage and friends via descriptors on the instance. This works in Chrome <43 but not in Safari 7.0 where even instance descriptors are not configurable.

Potential fix would be to return a proxy object similar to how patchClass works and intercept all of the property getters and setters via the proxy.

Support for non-browser environments

Currently the Zone implementation relies on the window object and cannot be used in a non-browser environment. It will be good if this dependency is abstracted away so we can load this in NativeScript projects.

Do not create a new zone for every callback

Currently, zone.js creates a new zone every time a callback gets called:

z1 = window.zone;

setTimeout(() => {
  z2 = window.zone;

  setTimeout(() => {
    z3 = window.zone;
  }, 0);

}, 0);

expect(z1).not.toBe(z2);
expect(z1).not.toBe(z3);
expect(z2).not.toBe(z3);

Maybe we should create a new zone only when fork is called?

New Feature: onZoneDone

tl;dr I would like an onZoneDone callback to be called once the function passed in to run is complete, and any tree of async code spawned from that function.

I would like to request a new feature. When I first looked at zone.js I was under the impression that onZoneEnter and onZoneLeave "contained" the function that was invoked via run and any async code kicked off from that function. I discovered that instead a zone can enter and leave more than once.

For Example:

zone.onZoneEnter = function() {
  console.log('entering');
};
zone.onZoneLeave = function() {
  console.log('leaving');
};
zone.onZoneDone = function() {
  console.log('All done finally');
};
zone.run(function() {
  console.log('hello');
  setTimeout(function() {
    console.log('this happened later');
  }, 3000);
});

This currently outputs:
entering
hello
leaving
leaving
entering
this happened later
leaving

I'd like it to output:
entering
hello
leaving
leaving
entering
this happened later
leaving
All done finally

You'll see that onZoneDone gets called after the last remaining setTimeout completes.

@btford

Publish 0.4.2!

Good news! With the fixes introduced since 0.4.1 shipped, the angular 2 demo apps work beautifully on WebKit Nightly. (Unfortunately, failures in shipped versions of Safari, due to broken Map implementation in JSC, and likely other things).

It would be great to be able to run tests against WKNightly so that there's a bit more coverage for iOS support, but first things first, we should publish the latest fixes and use them in the angular tree.

Create unique ID for each zone.

One of the reasons why debugging zones is hard is that it is hard to quickly tell if you have the same zone. I think it would be useful to append a unique id to each zone. Looking at the id would than give you the path.

123>4324>angular>root

It would probably mean that we could have a global counter. and the either expect the caller to supply the zone name in the fork or use the global counter to create o new id

Does not seem to be browserify compatible

Even if I try to:

window.zone = require('zone.js');

I get zone is not defined because the function Zone.patchSetClearFn assumes window.zone exists (i.e. in line 133).

Perhaps Zone.init should just installs on window.zone independently of module.exports, but export the created instance as well.

Any thoughts?

Long stack trace zones & fork

Currently lst fork is as follow:

  fork: function (locals) {
    var newZone = this._fork(locals);
    newZone.constructedAtException = Zone.getStacktrace();
    newZone.constructedAtTime = Date.now();
    return newZone;
  },

  _fork: zone.fork

Which is wrong because:

    zone // in zone A
      .fork({ // B
        '+fork': function() { log.push('fork'); }
      })
      .fork(Zone.longStackTraceZone) // C
      .fork(); // D

When creating the zone C, _fork will be set to the current zone's fork, which is zone A. The log is ['fork'] where it should be ['fork', 'fork'] for C, D.

I can not think of an easy fix for now.

My first thought was var newZone = this.parent.fork(locals); the issue is that it will recursively call fork() on the parent for forked zones.

Zone is eating exceptions

If library throws a non Error exception then Zone eats the exception in console. See: Chrome bug 460386

The issue is in zone.js

This code:

    try {
      this.beforeTask();
      result = fn.apply(applyTo, applyWith);
    } catch (e) {
      if (zone.onError) {
        zone.onError(e);
      } else {
        throw e;
      }
    } finally {
      this.afterTask();
      window.zone = oldZone;
    }

should be rewritten as:

 try {
    if (zone.onError) {
      try {
        this.beforeTask();
        result = fn.apply(applyTo, applyWith);
      } catch (e) {
          zone.onError(e);
      }
    } else {
      this.beforeTask();
      result = fn.apply(applyTo, applyWith);
    }
  } finally {
    this.afterTask();
    window.zone = oldZone;
  }

the key is that if zone.onError is not defined we should not catch the exception and rethrow as not to destroy the stacktrace.

Create bindPromiseFn which converts a non native Promise to Native Promise

Similar to bind() have a method which would allow us to easily capture zone on methods which instead of taking callbacks return Promise

function bindPromiseFn(delegate) {
  return function() {
    var delagtePromise = delegate.apply(this, arguments);
    if (deletaePromise instanceof Promise) {
      return delegatePromise;
    } else {
      return new Promise(function(resolve, reject) { 
        delegatePromise.then(resolve, reject); 
      });
    }
 };
}

See the workaround I had to do to fix an issue: https://github.com/rkirov/youtube-app/pull/1/files

Should `run()` always rethrows ?

Let's say you have this code:

promise.then(<fn that throws>).then(resolve, reject);

<fn that throws> is executed by the run() method, if the exception handler does not rethrow the error, resolve will get called instead of reject which will break the expected execution flow.

We could decided:

  • to always rethrow the exception even if an error handler is defined (via onError),
  • leave the choice to the user, but it is then very easy to shot yourself in the foot.

Thoughts ?

Run Digest cycle

In the video, you said, that with zonejs you can fix the .$digest, $appy, so we wont have to call it manually any more.

Can you please point me to the example, or maybe I understood it wrong.

feat: support htmlimports

var link = document.createElement('link');
link.rel = 'import';
link.href = 'someUrl';
link.onload = ...
link.onerror = ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.