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

Remove references to unused properties #1187

Closed
Rich-Harris opened this issue Feb 24, 2018 · 2 comments
Closed

Remove references to unused properties #1187

Rich-Harris opened this issue Feb 24, 2018 · 2 comments

Comments

@Rich-Harris
Copy link
Member

Post-#1122 cleanup:

{{#each things as thing}}
  <p>{{thing}}</p>

  {{#if true}}
    <p>thing is unused</p>
  {{/if}}
{{/each}}
function create_main_fragment(component, state) {
  var each_anchor;

  var things = state.things;

  var each_blocks = [];

  for (var i = 0; i < things.length; i += 1) {
    each_blocks[i] = create_each_block(component, assign({}, state, {
-      thing: things[i],
-      thing_index: i
+      thing: things[i]
    }));
  }

  return {
    c: function create() {
      for (var i = 0; i < each_blocks.length; i += 1) {
        each_blocks[i].c();
      }

      each_anchor = createComment();
    },

    m: function mount(target, anchor) {
      for (var i = 0; i < each_blocks.length; i += 1) {
        each_blocks[i].m(target, anchor);
      }

      insertNode(each_anchor, target, anchor);
    },

    p: function update(changed, state) {
      var things = state.things;

      if (changed.things) {
        for (var i = 0; i < things.length; i += 1) {
          var each_context = assign({}, state, {
-            thing: things[i],
-            thing_index: i
+            thing: things[i]
          });

          if (each_blocks[i]) {
            each_blocks[i].p(changed, each_context);
          } else {
            each_blocks[i] = create_each_block(component, each_context);
            each_blocks[i].c();
            each_blocks[i].m(each_anchor.parentNode, each_anchor);
          }
        }

        for (; i < each_blocks.length; i += 1) {
          each_blocks[i].u();
          each_blocks[i].d();
        }
        each_blocks.length = things.length;
      }
    },

    u: function unmount() {
      for (var i = 0; i < each_blocks.length; i += 1) {
        each_blocks[i].u();
      }

      detachNode(each_anchor);
    },

    d: function destroy() {
      destroyEach(each_blocks);
    }
  };
}

// (1:0) {{#each things as thing}}
function create_each_block(component, state) {
-  var thing = state.thing, thing_index = state.thing_index;
+  var thing = state.thing;
  var p, text_value = thing, text, text_1, if_block_anchor;

  var if_block = (true) && create_if_block(component, state);

  return {
    c: function create() {
      p = createElement("p");
      text = createText(text_value);
      text_1 = createText("\n\n\t");
      if (if_block) if_block.c();
      if_block_anchor = createComment();
    },

    m: function mount(target, anchor) {
      insertNode(p, target, anchor);
      appendNode(text, p);
      insertNode(text_1, target, anchor);
      if (if_block) if_block.m(target, anchor);
      insertNode(if_block_anchor, target, anchor);
    },

    p: function update(changed, state) {
      thing = state.thing;
-      thing_index = state.thing_index;
      if ((changed.things) && text_value !== (text_value = thing)) {
        text.data = text_value;
      }

      if (true) {
        if (!if_block) {
          if_block = create_if_block(component, state);
          if_block.c();
          if_block.m(if_block_anchor.parentNode, if_block_anchor);
        }
      } else if (if_block) {
        if_block.u();
        if_block.d();
        if_block = null;
      }
    },

    u: function unmount() {
      detachNode(p);
      detachNode(text_1);
      if (if_block) if_block.u();
      detachNode(if_block_anchor);
    },

    d: function destroy() {
      if (if_block) if_block.d();
    }
  };
}

// (4:1) {{#if true}}
function create_if_block(component, state) {
-  var thing = state.thing, thing_index = state.thing_index;
+  var thing = state.thing;
  var p;

  return {
    c: function create() {
      p = createElement("p");
      p.textContent = "thing is unused";
    },

    m: function mount(target, anchor) {
      insertNode(p, target, anchor);
    },

-    p: function update(changed, state) {
-      thing = state.thing;
-      thing_index = state.thing_index;
-
-    },
+    p: noop,

    u: function unmount() {
      detachNode(p);
    },

    d: noop
  };
}
@Rich-Harris
Copy link
Member Author

also, from #1220

A neater solution would determine that the click handler only needed the animal value and didn't need to get it in a convoluted way, so we could just pass that around instead of the array and the index

Rich-Harris added a commit that referenced this issue Apr 29, 2018
Rich-Harris added a commit that referenced this issue Oct 28, 2018
Rich-Harris added a commit that referenced this issue Oct 28, 2018
only add list/index to each block context if necessary
@Rich-Harris
Copy link
Member Author

fixed in #1383

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

No branches or pull requests

2 participants