sirtimbly/frets

Add plugin registration feature

sirtimbly opened this issue · 2 comments

I want it to be possible to register new functionality in a simple developer friendly and async way.

Developers should be able to include a UI rendering function that takes an instance of the FRETS class and enhance it with it's own necessary actions, data properties, and calculation and validation functionality.

Approach: Add a third parameter to the standard UI rendering function signature, an instance of the FRETS class. When a plugin needs to be registered, all of it's action methods are added to the actions of the FRETS instance. A calculate function can be patched with a new function (maybe one that calls next() at the end?). The validate function can be patched in the same way. The data properties class can be extended with additional properties. When the App is extended with this plugin the extend/register function should return a new instance of the props and the actions classes so that developers still get great intellisense and strong typing when accessing "actions" or "props" internally.

Research this approach: https://hapijs.com/tutorials/plugins

Things to avoid:

  • adding internal state to the rendering function which is expected to persist between renders.
  • making the developer remember if something is available on the props or actions through magic strings or magic property names that can't be hinted from the IDE.

Note to self: Remember to look at ES7 decorators...

I'm not sure I've come up with any good reasons to do this yet. The registerField methods seem to handle a lot of this.