{"action":"created","issue":{"url":"https://api.github.com/repos/vkarpov15/kareem/issues/3","labels_url":"https://api.github.com/repos/vkarpov15/kareem/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/vkarpov15/kareem/issues/3/comments","events_url":"https://api.github.com/repos/vkarpov15/kareem/issues/3/events","html_url":"https://github.com/vkarpov15/kareem/issues/3","id":71241012,"number":3,"title":"grappling-hook","user":{"login":"creynders","id":436347,"avatar_url":"https://avatars.githubusercontent.com/u/436347?v=3","gravatar_id":"","url":"https://api.github.com/users/creynders","html_url":"https://github.com/creynders","followers_url":"https://api.github.com/users/creynders/followers","following_url":"https://api.github.com/users/creynders/following{/other_user}","gists_url":"https://api.github.com/users/creynders/gists{/gist_id}","starred_url":"https://api.github.com/users/creynders/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/creynders/subscriptions","organizations_url":"https://api.github.com/users/creynders/orgs","repos_url":"https://api.github.com/users/creynders/repos","events_url":"https://api.github.com/users/creynders/events{/privacy}","received_events_url":"https://api.github.com/users/creynders/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-27T10:13:10Z","updated_at":"2015-04-27T12:58:11Z","closed_at":null,"body":"Hi @vkarpov15 \r\n\r\nFirst a little background before I come to my question. I'm a core team member of [keystone](/keystonejs/keystone) and recently we needed some hooking functionality. So I started scouring over the many hooking modules (`hooks`, `hooks-fixed`, `kareem`, etc) and thought kareem definitely looked the most promising. However, we also needed a bunch of things that weren't provided out-of-the-box so at first I tried to adapt kareem to our needs. As it always goes, I ended up writing my own hooking module from scratch, thinking it would be faster to write one than adapting yours (it probably wasn't :smile: )\r\nAnyway, this became [`grappling-hook`](/keystonejs/keystone). Due to the fact we use and expose `mongoose` in `keystone` I really wanted to make the `pre` and `post` registration API compatible to mongoose's, in order to present users with a single hooking API, whether they're hooking into mongoose or keystone. It's not 100% compatible ATM, but will be pretty trivial to do so.\r\nAnyway, I can imagine you have a LOT of work with mongoose and was wondering if you'd be interested in considering using grappling-hook in mongoose. I had a superficial look at mongoose and it seems to me it would cost me _very_ little effort to make `grappling-hook` a drop-in replacement for both kareem and hooks-fixed, but providing a bunch of extra functionality out-of-the-box, e.g. parameter passing to pre middleware, more granular control over post sequencing, a number of sugary methods which allow you to introspect middleware et cetera.\r\nGranted, it was a superficial look and I'd definitely need to compare performance with kareem. In our case performance is not such an issue, so I definitely haven't optimised the hell out of it.\r\nJust giving you a heads-up that I wrote something similar, and will actively maintain it, with promises integration on the roadmap for instance.\r\n\r\n**Please do not misunderstand me**, I'm **not** suggesting this because kareem is badly written or so **AT ALL** (again: **AT ALL**). My main motivation is that I really want to help make keystone the best it can become and to _us_ it would be really cool to be 100% sure the hooking mechanism in keystone and mongoose is identical. And the benefit I think it could have for _you_ is being freed of a small yet essential part of functionality of mongoose. \r\nIf it doesn't interest you: I _TOTALLY_ understand, if so, sorry for bothering you with this silliness."},"comment":{"url":"https://api.github.com/repos/vkarpov15/kareem/issues/comments/96640981","html_url":"https://github.com/vkarpov15/kareem/issues/3#issuecomment-96640981","issue_url":"https://api.github.com/repos/vkarpov15/kareem/issues/3","id":96640981,"user":{"login":"vkarpov15","id":1620265,"avatar_url":"https://avatars.githubusercontent.com/u/1620265?v=3","gravatar_id":"","url":"https://api.github.com/users/vkarpov15","html_url":"https://github.com/vkarpov15","followers_url":"https://api.github.com/users/vkarpov15/followers","following_url":"https://api.github.com/users/vkarpov15/following{/other_user}","gists_url":"https://api.github.com/users/vkarpov15/gists{/gist_id}","starred_url":"https://api.github.com/users/vkarpov15/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vkarpov15/subscriptions","organizations_url":"https://api.github.com/users/vkarpov15/orgs","repos_url":"https://api.github.com/users/vkarpov15/repos","events_url":"https://api.github.com/users/vkarpov15/events{/privacy}","received_events_url":"https://api.github.com/users/vkarpov15/received_events","type":"User","site_admin":false},"created_at":"2015-04-27T12:58:11Z","updated_at":"2015-04-27T12:58:11Z","body":"Worth noting - I consider hooks and hooks-fixed to be deprecated. hooks-fixed only exists because I don't have push access to hooks and hooks has several critical bugs. grappling-hook is worth investigating, I like the idea of collaborating on code where possible, but there are 3 features / things that I really need from a hooks library going forward -\r\n\r\n1) Executing hooks attached to a different object. In mongoose we need to recreate hooks every time we create a new doc or subdoc, which is pretty wasteful (see Automattic/mongoose#2809). Much of the point of kareem was \"attach hooks once to schema, call them from wherever\" as opposed to \"execute complex logic to add hooks to prototype every single time a doc is created.\" I may be able to implement this with callHook's context param but I want to be sure.\r\n2) 100% test coverage. It's not a guarantee of being bug-free, but it's a good start.\r\n3) Promises support. See Automattic/mongoose#2754. Mongoose does a lot of nasty things to make hooks play nice with promises. Kareem doesn't have built-in support for promises, but being able to do `execPre()`, `execPost()`, and `wrap()` gives me the ability to just use mongoose's promises.\r\n\r\nI'm curious to see if I can do 1) and 3) with grappling-hook. What do you think?"}}