Vulcan icon indicating copy to clipboard operation
Vulcan copied to clipboard

New callback syntax

Open eric-burel opened this issue 5 years ago • 2 comments

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.

eric-burel avatar Feb 28 '20 08:02 eric-burel

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.

SachaG avatar Mar 02 '20 07:03 SachaG

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.

eric-burel avatar Mar 02 '20 07:03 eric-burel