Maximum Flexible Hook
Adding hook at everywhere, with every type, every interface, run on every mode to your function.
Example
Assume you have an order
const order = id : 10000 customer_id : 1000 user_id : 2000 items : id : 1000 price : 200 quantity : 2 id : 2000 price : 500 quantity : 2 ;
The following function generates excel rows for each order item, it does nothing except calling hooks
{ return { const it = order summary result : rows : ; await ; for let item of orderitems itsession = item row : {} ; ; itresultrows; ; return itresult; }} const generateRows = ;
Then you can add some hooks
generateRows ;
Add it works
const summary = total_price : 0 total_quantity : 0 ; const rows = await ; const expectedRows = order_id : 10000 user : 'Bar' title : 'Nokia N7' price : 200 net : 180 quantity : 2 total_price : 400 order_id : 10000 user : 'Bar' title : 'Iphone 5' price : 500 net : 400 quantity : 2 total_price : 1000 ; const expectedSummary = total_price : 1400 total_quantity : 4 ; assert; assert;
Also, support cloning to reusing and extending
const generateRowsWithCustomer = generateRows; generateRowsWithCustomer; const summary = total_price : 0 total_quantity : 0 ; const rows : rowWithCustomer = await ; const expectedRowsWithCustomer = order_id : 10000 customer : 'Foo' user : 'Bar' title : 'Nokia N7' price : 200 net : 180 quantity : 2 total_price : 400 order_id : 10000 customer : 'Foo' user : 'Bar' title : 'Iphone 5' price : 500 net : 400 quantity : 2 total_price : 1000 ; assert;
And custom hookable interface with extender
const extender = { func { hookStore; return func; } func { hookStore; return func; } func { hookStore; return func; } return func;} // or use built-in creatorconst extender = Hookableextender; const generateRowsWithCustomExtender = ; generateRowsWithCustomExtender;
Topics
Allow client choose which hooks will be invoked with ObjectHookStore
const HookableFactory HookStores = ; const Hookable = ; const hookA = code : 'A' itresult ;const hookB = code : 'B' itresult ;const hookC = code : 'C' itresult ; const f = ; f; assert; assert;