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

unit test for if helper inside each helper problem #1

Merged
merged 1 commit into from
May 2, 2016

Conversation

steveh80
Copy link

Added an unit test that shows the problem with if helper inside each helper that leads to a context loss.

I can’t provide a solution for that, but I hope this unit test helps you solve that problem.

Btw. I added that unit test to the handlebars.js project too and there it passes.

@doowb
Copy link
Member

doowb commented Apr 27, 2016

Thanks! I'll take a look at this today.

@zeitiger
Copy link
Contributor

zeitiger commented May 2, 2016

in my point of view

ret = ret + fn(context[field], {
      data: data,
      blockParams: utils.blockParams([context[field], field], [contextPath + field, null])
    });

doesn't change the context within the each block, because

context.helpers = utils.bindAll(helpers, thisArg, {
      bindFn: function(thisArg, key, options) {
        var namespace = thisArg.app._namespace || 'base:templates';
        thisArg.debug = debug(namespace + ':helper:' + key);
        setHelperOptions(thisArg, key);
        thisArg.helper.name = key;
        return thisArg;
      }
    });

pinned this for all helper and the context reference within if helper like this

if ((!options.hash.includeZero && !conditional) || utils.isEmpty(conditional)) {
    return options.inverse(this.context);
  } else {
    return options.fn(this.context);
  }

is frozen to root context.

{{#each items}}{{#if foo}}{{foo}}{{/if}}{{/each}} could be alternative write to {{#each items as |value|}}{{#if value.foo}}{{value.foo}}{{/if}}{{/each}} as workaround

@doowb
Copy link
Member

doowb commented May 2, 2016

Thank you @zeitiger for the additional information. This helps and gives me a better starting point of where to look.

@doowb doowb merged commit b83ebed into assemble:master May 2, 2016
@doowb
Copy link
Member

doowb commented May 2, 2016

@steveh80 I tracked down where we can make some changes to make this work. I'll get a new version published when we get the other changes done.

@jonschlinkert
Copy link
Member

@zeitiger thanks for the investigative work, that really helped!

@doowb
Copy link
Member

doowb commented May 3, 2016

@steveh80 please try this with the latest assemble and let me know if you're still having issues.

@zeitiger
Copy link
Contributor

zeitiger commented May 3, 2016

Further information, like #each also #with will not a apply a new context.

@doowb
Copy link
Member

doowb commented May 3, 2016

If you get the latest assemble and make sure everything is installed fresh, the helpers should be correct. The {{#if}} helper is using the parent context which will be the context set with {{#each}} and {{#with}}. If there are other bugs, please open a new issue so we can discuss them and get them fixed. Thanks for your time and help @zeitiger and @steveh80

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants