Skip to content
This repository has been archived by the owner on Nov 2, 2021. It is now read-only.

version 1 #1

Merged
merged 24 commits into from
Mar 23, 2015
Merged

version 1 #1

merged 24 commits into from
Mar 23, 2015

Conversation

creynders
Copy link
Contributor

@JedWatson just pushed the first version to a v1 branch. Let me know what you think of the API.
I've expanded it to include some very useful methods.

In a nutshell, the API's:

  • pre

  • post

  • hookup Sets up a hook.

    field.hookup('pre:save', fn);
    //equals:
    field.pre('save', fn);
  • hookable (used to be register)

    field.hookable('pre:save'); //only allows 'pre:save' hooks
    field.hookable('save'); //allows 'pre:save' and 'post:save' hooks
  • hooks iterates over all hooks

  • emit calls hooks

    field.emit("pre:save", foo, bar); // all "pre:save" hooks called with foo and bar as parameter
  • unhook removes a hook

     //removes `onFieldSave` as a `pre:save` hook
     field.unhook( 'pre:save', onFieldSave );
     //removes ALL hooks for `pre:save`
     field.unhook('pre:save');
     //removes ALL `pre` hooks
     field.unhook('pre');
     //removes ALL hooks, i.e. `pre` AND `post`
     field.unhook();
  • hooked wraps a method with pre and post emissions

    field.save = function(){
        console.log('SAVE');
    }
    field.hooked("save");
    field.pre("save", function(){
      console.log("pre:save called");
    });
    field.save();
    //outputs:
    //pre:save called
    //SAVE

Tests aren't finished yet and I need to add a few more sanity checks

@creynders
Copy link
Contributor Author

Updated API and tests. WARNING: this depends on an unpublished version of asyncdi where all my PR's have been merged into.

@JedWatson JedWatson mentioned this pull request Mar 16, 2015
@creynders
Copy link
Contributor Author

@JedWatson good to go I think, but the new version of asyncdi needs to be published first. I assumed it'll be v1.1.0 ...

@JedWatson
Copy link
Member

Nice work! Merging for final review / collaboration / release 😄

JedWatson added a commit that referenced this pull request Mar 23, 2015
@JedWatson JedWatson merged commit 2ec25f6 into master Mar 23, 2015
@JedWatson JedWatson deleted the v1 branch March 23, 2015 12:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants