Skip to content

Instantly share code, notes, and snippets.

@deepak
Created February 14, 2017 12:57
Show Gist options
  • Save deepak/036f048502449baae7ee0fbaa4789160 to your computer and use it in GitHub Desktop.
Save deepak/036f048502449baae7ee0fbaa4789160 to your computer and use it in GitHub Desktop.

Revisions

  1. deepak created this gist Feb 14, 2017.
    29 changes: 29 additions & 0 deletions use-currying.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    let MODIFY = "MODIFY";
    let ADD = "ADD";
    let DELETE = "DELETE";

    function checkAction(actions, recon, action, cb) {
    if (actions.indexOf(action) > -1) {
    cb(recon);
    }
    }

    function buildRecon() {
    let actions = [
    MODIFY,
    // ADD,
    DELETE
    ];

    let reconActions = [];
    let factory = checkAction.bind(null, actions, reconActions);

    factory(MODIFY, (arr) => { arr.push(`pushed ${MODIFY}`); });
    factory(ADD, (arr) => { arr.push(`pushed ${ADD}`); });
    factory(DELETE, (arr) => { arr.push(`pushed ${DELETE}`); });

    return reconActions;
    }

    let reconActions = buildRecon();
    console.dir(reconActions);