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

{{#with}} Mustache helper pushes can.compute into Scope, breaks can.compute.read #871

Closed
bmomberger-reciprocity opened this Issue Apr 4, 2014 · 1 comment

Comments

Projects
None yet
2 participants
@bmomberger-reciprocity
Contributor

bmomberger-reciprocity commented Apr 4, 2014

http://jsfiddle.net/air_hadoken/8Ss9P/

I'm entirely unsure which function is in the wrong here, but here's the breakdown.

view/mustache/mustache.js, line 1996:

                'with': function(expr, options) {
                    var ctx = expr;
                    expr = Mustache.resolve(expr);
                    if ( !! expr) {
                        return options.fn(ctx);
                    }
                },

expr is resolved and checked from ctx, as the result of executing ctx when ctx is a can.compute or a function. Then ctx (which may be a compute) is pushed onto the current Scope and the inner content of the {{#with}} block is run. If we try to then get attributes on the scope, there's an error thrown later.

Possible solution #1: options.fn(expr) instead of options.fn(ctx) -- this seems to be inline with https://github.com/wycats/handlebars.js/blob/master/spec/builtins.js which implies that the scope of a {{#with}} block includes the result of calling the function, not the function itself.

compute/compute.js, line 443, in can.compute.read:

        cur = cur.attr(reads[i]);

In the case of {{#with}}, cur starts out as a compute, and is not resolved, but prev is resolved to a can.Map, leading to this line of execution. cur does not have an attr function available; this is where the crash ultimately happens.

Possible solution #2: resolve cur if cur.isComputed at the beginning of can.compute.read

Doing both of the possible solutions is probably good for CYA against this happening again, but I'd like to hear from people who have worked on these modules.

@daffl daffl added this to the 2.3.0 milestone Oct 22, 2015

@daffl

This comment has been minimized.

Contributor

daffl commented Oct 22, 2015

This is fixed in 2.3.0

@daffl daffl closed this Oct 22, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment