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 unnecessary current_block && #540

Closed
Rich-Harris opened this issue May 1, 2017 · 0 comments · Fixed by #556
Closed

Remove unnecessary current_block && #540

Rich-Harris opened this issue May 1, 2017 · 0 comments · Fixed by #556

Comments

@Rich-Harris
Copy link
Member

Very minor thing I noticed while working on #525 — if you have an if block (or a chain of if, elseif, elseif...) followed by an else block, then there's no need to check for the existence of current_block:

function get_block ( state ) {
  if ( state.foo ) return create_if_block;
  return create_if_block_1;
}

var current_block = get_block( state );
-var if_block = current_block && current_block( state, component );
+var if_block = current_block( state, component );

return {
  mount: function ( target, anchor ) {
    // ...
  },

  update: function ( changed, state ) {
    // ...

    if ( current_block !== ( current_block = get_block( state ) ) ) {
-      if ( if_block ) if_block.destroy( true );
-      if_block = current_block && current_block( state, component );
-      if ( if_block ) if_block.mount( if_block_anchor.parentNode, if_block_anchor );
+      if_block.destroy( true );
+      if_block = current_block( state, component );
+      if_block.mount( if_block_anchor.parentNode, if_block_anchor );
    }
  },

  destroy: function ( detach ) {
    // ...
-    if ( if_block ) if_block.destroy( detach );
+    if_block.destroy( detach );
  }
};

This'll have to wait until after #525 in order to avoid merge conflicts.

Rich-Harris added a commit that referenced this issue May 4, 2017
generate less code for if-blocks with else-blocks
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 a pull request may close this issue.

1 participant