Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hooks #79

Open
alexewerlof opened this issue Aug 15, 2020 · 1 comment · May be fixed by #84
Open

Hooks #79

alexewerlof opened this issue Aug 15, 2020 · 1 comment · May be fixed by #84

Comments

@alexewerlof
Copy link
Owner

Current behaviour

The renderFn() and renderFnAsync() seem to be mainly underused if I am to trust Github search.
This feature is one of the killer features of micromustache, so let's rethink how to make it more intuitive.

Expected behavior

Add the possibility to process paths before and after they are resolved using get(). This can allow HTML escaping for example. Also see #50

The code (and its usage) will be simpler if we have some steps for resolving and allow hooks to be implemented to modify the default behaviour:

  1. before the path is parsed
  2. after the path has turned into a ref but before that ref is resolved from the scope
  3. after the value is resolved from the scope and before it is being interpolated

At each step, a hook can modify its input, throw, or cancel the rest of the chain

Also it should be possible to disable a step (say get() for example)

That way we can have only two methods: render() and renderAsync() and the hooks can be passed as options.

@alexewerlof
Copy link
Owner Author

alexewerlof commented Aug 15, 2020

To keep the lib small and focused, it's better to offload this to the user to do whatever they want.
The users can easily achieve this using the tokenize() and get() (or parsePath() and getRef()).
This can be documented as "tips and tricks".
This will simplify the library code while giving a huge flexibility to the user to implement their resolving pipeline with whatever parsing or sanetization they may choose to have.
A side effect of this refactoring is that finally we can have progressive tokenization, parsing and stringification that are nice to the JavaScript event loop and don't block it.

@alexewerlof alexewerlof linked a pull request Aug 17, 2020 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant