8000 Remove unnecessary `current_block &&` · Issue #540 · sveltejs/svelte · GitHub
[go: up one dir, main page]

Skip to content
Remove unnecessary current_block && #540
Closed
@Rich-Harris

Description

@Rich-Harris

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0