Comments (4)
If you're the one that added hookable
as a dependency I created a package that is the same thing but only uses sync functions
from hookable.
Event Emitter is probably the closest (and best-optimized solution performance-wise - next to plain functions) for the sync method. sync-hookable
also seems a good option thanks @Vinccool96!
Here are the options in summary:
- Use beforeEach/affterEach sync callbacks for logging (you can filter based on event name)
- Use an alternative like
sync-hookable
- Use Node.js Event Emitter
- Use plain callback functions for simpler cases
from hookable.
All hookable internals are asynchronous. There are only interceptors you can add and are sync.
By the current code, I would use two simple callback options instead but if you can give more context of your project and usage can help better me understanding.
from hookable.
We are using the RxJS WebSocketSubject to handle asynchronous messages. However the serializer
and deserializer
in WebSocketSubjectConfig are synchronous functions. We added the hooks and it works fine, but we wanted to find out if we could make the hooks synchronous. Similar to how we call the other hooks with:
await hooks.callHook(Hook.SOME_HOOK, data)`.
We currently just use these hooks for logging, so that works fine, however we were wondering if we can intercept the message using a hook to transform the incoming msg
similar to a middleware pattern e.g.
function serializer(msg: Message): WebSocketMessage {
const transformedMsg = hooks.callHookSync(Hook.BEFORE_SERIALIZED, msg)
const serialized = serialize(transformedMsg)
return hooks.callHookSync(Hook.SERIALIZED, serialized)
}
from hookable.
Related Issues (19)
- Cannot find module 'hable' HOT 1
- Fully typed nested/namespaced hooks (for `addHooks`) HOT 2
- TypeScript Examples HOT 7
- `callHookSync`
- Allow differed hook calling
- hook events
- Action Required: Fix Renovate Configuration
- Dependency Dashboard
- closed
- Debugger
- Is there a way to clear all hooks? HOT 3
- Debugger handling parallel hook calls with same name
- Type 'HooksT' does not satisfy the constraint 'Record<string, any>' HOT 4
- set caller
- Allow to return value from callback function HOT 1
- Uncaught SyntaxError: Unexpected token { HOT 2
- Typescript: Template class extend Hookable type issue
- Allow register hooks with `enforce: before|after`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hookable.