angular / zone.js Goto Github PK
View Code? Open in Web Editor NEWImplements Zones for JavaScript
Home Page: https://github.com/angular/angular/tree/master/packages/zone.js/
License: MIT License
Implements Zones for JavaScript
Home Page: https://github.com/angular/angular/tree/master/packages/zone.js/
License: MIT License
zone.js repo
has been moved to angular mono repo
here, This repo has been archived. Please create issue in angular repo. Thanks!Seems to cause an issue with the Polymer runtime.
See commit e9dfbed
Setting xhr.responseType = 'document'
is a noop right now (given xhr = new XMLHttpRequest()
).
In https://github.com/angular/zone.js/blob/master/zone.js#L347 the else case is missing, i.e.
if (typeof fn === 'function') {
this._o[prop] = zone.bind(fn);
} else {
this._o[prop] = fn;
}
It's called vizone... Generates a flow chart of application flow...
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
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?
This is broken in Safari 8 and WebKit nightly, shouldn't hurt more spec-compliant browsers.
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');
}
};
}
right now, the tests likely fail because of it.
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
.
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
.
Seems like some CJS tests are broken: https://travis-ci.org/angular/zone.js/builds/60753797#L204
Looks like it is related to #73
@unframework do you have some time to take a look at it ?
window.onhashchange
window.addEventListener
(already done)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.
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?
The first implementation of zone + microtask (see #82) works as follow:
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.
Promise
, see kriskowal/asap#54, http://blog.millermedeiros.com/promise-nexttick/, http://jsperf.com/test002/8If 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
When using zone.js together with mozilla bricks, I get the following error.
Plunker: http://plnkr.co/edit/LuKeHXiVUKRjLa3FuM5e?p=preview
Uncaught TypeError: Cannot assign to read only property 'createdCallback' of #<HTMLElement> zone.js:528
(anonymous function) zone.js:528
document.registerElement zone.js:526
xtag.register brick.js:1242
(anonymous function) brick.js:1797
(anonymous function)
This needs some investigation.
Currently RxJS doesn't cause zone hooks to fire. @vsavkin gave me this example: vsavkin/angular@2d0a849
I think this is re relevant section of the implementation โ https://github.com/Reactive-Extensions/RxJS/blob/47cbafa678c0e4f66c7307c8b8ecaab3407444fb/src/core/concurrency/timeoutscheduler.js
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
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.
Here's the trace:
TypeError: Cannot read property '_bound' of undefined
at HTMLButtonElement.obj.removeEventListener (http://localhost:9001/bower_components/zone/zone.js:296:19)
at http://localhost:9001/bower_components/angular/angular.js:2274:46
at http://localhost:9001/bower_components/angular/angular.js:2429:9
at Array.forEach (native)
at forEach (http://localhost:9001/bower_components/angular/angular.js:320:11)
at jqLiteOff (http://localhost:9001/bower_components/angular/angular.js:2427:5)
at Object.JQLite.(anonymous function) (http://localhost:9001/bower_components/angular/angular.js:3099:17)
at Object.fn (http://localhost:9001/app/directives/helper.js:133:29)
at Scope.$digest (http://localhost:9001/bower_components/angular/angular.js:12533:29)
at Scope.$apply (http://localhost:9001/bower_components/angular/angular.js:12798:24)
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
via @tbosch
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?
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.
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.
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.
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.
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?
The CI fails.
Seems to be linked to firefox, see https://travis-ci.org/angular/zone.js/builds/55827284#L164
I had to xit the test "should work with onmessage" because it does not work.
This should be investigated.
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
I run the first example in the chrome console,but the result is :
in the zone: true
undefined
in the zone: true
I'm just confused about it.
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.
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
JSC being eager to report these errors --- engines all do different things here, so it's not a great idea to do this anyhow.
Really need to get Safari tests running on CI :(
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?
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.
I pulled this out into its own lib: https://github.com/btford/property-lolscriptors
I think I want to use browserify to build this.
Currently there is no other way than looking at the commits to get the changes in each releases
Steps to reproduce.
Shell:
jspm install github:angular/zone.js
App:
import 'angular/zone.js`
Result: zone is not defined
@ zone.js#125
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.
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
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:
onError
),Thoughts ?
see how this is done in angular/angular or angular/angular.js
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.
var link = document.createElement('link');
link.rel = 'import';
link.href = 'someUrl';
link.onload = ...
link.onerror = ...
The following line:
Line 663 in 26a4dc2
Checks if (opts.prototype[callback])
and then uses Object.getOwnPropertyDescriptor(opts.prototype, callback)
to retrieve it. If the callback comes from the prototype chain we cannot use getOwnPropertyDescriptor
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.