Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle observations being left on the stack #27

phillipskevin opened this issue Oct 20, 2016 · 1 comment

Handle observations being left on the stack #27

phillipskevin opened this issue Oct 20, 2016 · 1 comment


Copy link

@phillipskevin phillipskevin commented Oct 20, 2016

It is possible for an observation to be left on the observationStack here, for instance if a compute throws:

var c = compute(function(){
    throw new Error('oh noes!');

try {
    c.bind('change', function(){});
} catch(e) {
    Observation.isRecording(); // !!false

This can cause strange behavior because all computes will act as if they are bound. For example, in the code below resolve will be defined in the asynchronous getter for foo even though nothing is binding on foo:

var M = CanMap.extend({
    define: {
        foo: {
            get: function(set, resolve) {
                if (resolve) {

var m = new M();

m.attr('foo'); // 'bar'

We should consider warning people when this happens so that they can either:

  1. handle thrown errors within their computes
  2. use something like{...}) which we could provide to wrap the function call in a try/catch

We can tell if this happens by polling Observation.isRecording() with a setTimeout. If it is ever true, it means that something was not popped off the stack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.