Skip to content

Add missing keys on context of EachHelper#543

Merged
jknack merged 1 commit intojknack:masterfrom
giflw-forks:patch-3
May 24, 2018
Merged

Add missing keys on context of EachHelper#543
jknack merged 1 commit intojknack:masterfrom
giflw-forks:patch-3

Conversation

@giflw
Copy link
Copy Markdown
Contributor

@giflw giflw commented Sep 27, 2016

Add @key to Iterable and @index to Map as in handlebars.js, where iterables and maps use the same helper function execIteration (https://github.com/wycats/handlebars.js/blob/master/lib/handlebars/helpers/each.js) (2016-09-27).

line 22:

    function execIteration(field, index, last) {
      if (data) {
        data.key = field;
        data.index = index;
        data.first = index === 0;
        data.last = !!last;
      }

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

line 36:

 if (context && typeof context === 'object') {
      if (isArray(context)) {
        for (let j = context.length; i < j; i++) {
          if (i in context) {
            execIteration(i, i, i === context.length - 1);
          }
        }
      } else {
        let priorKey;

        for (let key in context) {
          if (context.hasOwnProperty(key)) {
            // 3 lines of comments....
            if (priorKey !== undefined) {
              execIteration(priorKey, i - 1);
            }
            priorKey = key;
            i++;
          }
        }
        if (priorKey !== undefined) {
          execIteration(priorKey, i - 1, true);
        }
      }
    }

@coveralls
Copy link
Copy Markdown

coveralls commented Sep 27, 2016

Coverage Status

Coverage increased (+0.02%) to 86.226% when pulling 1380e37 on giflw:patch-3 into 1f6c48e on jknack:master.

@jknack jknack added this to the 4.0.7 milestone May 24, 2018
@jknack jknack merged commit 849fd5c into jknack:master May 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants