New callback syntax
Since we move to NPM, it's a good time to rethink a few things:
Proposal:
Callbacks = {}
// Init the Callbacks object with add and run method, handle nesting
// Equivalent to a `lodash.set(Callbacks, "whatever.foobar", { callbacks: [Â ], add: () => { Callacks.whatever.foobar.callbacks.push(yourCallback) }, run: () { /* TODO run registered callbacks for this path */ })
registerCallback('whatever.foobar')
// Store a callback in Callbacks.whatever.foobar.callbacks
Callbacks.whatever.foobar.add()
// Run callback in Callbacks.whatever.foobar.callbacks
Callbacks.whatever.foobar.run()
This way it's easy to create complex callbacks structure, using a string and namespaces, but also avoid mistakes in naming when running callbacks.
Why not. I think the important thing is getting CRUD callbacks right and I think the current API works pretty well. For "non-standard" callbacks I don't have a strong opinion but we should think about how to make them work well with typescript and VS Code.
Yeah this change wouldn't affect how they work with TS and VS Code, it will behave the same as with a string. Not sure either what's best, I'll leave the proposal here while we think about it. Its main advantage is having a syntax similar to CRUD operations.