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

Split output to separate module / library #132

Open
GreenImp opened this issue May 18, 2020 · 1 comment
Open

Split output to separate module / library #132

GreenImp opened this issue May 18, 2020 · 1 comment

Comments

@GreenImp
Copy link
Collaborator

GreenImp commented May 18, 2020

Is your feature request related to a problem? Please describe.
The roll output, that returns the string version of the roll log, is currently built in to the individual classes and is not easily changeable.
It could be helpful if the output was built as a separate module, so that it can be easily swapped out for a different output type. This would enable easier modification of the output and allow things like HTML output.

Describe the solution you'd like
Move the output functionality into it's own set of classes that can handle the various objects that need to be output.

It may be beneficial for this to be it's own library, rather than built in to the dice roller itself. The alternative is to simply build it inside the library as it's own set of modules.

@GreenImp GreenImp added this to the 4.3.0 milestone May 18, 2020
@GreenImp GreenImp changed the title Split out to separate class / library Split output to separate class / library May 18, 2020
@GreenImp GreenImp changed the title Split output to separate class / library Split output to separate module / library May 18, 2020
@GreenImp GreenImp removed this from the 4.3.0 milestone May 29, 2020
@GreenImp GreenImp mentioned this issue Feb 3, 2021
2 tasks
@GreenImp
Copy link
Collaborator Author

GreenImp commented Oct 13, 2022

Just a note on my thoughts at the moment:

We can probably achieve this in a similar way to the RNG, where we have a separate class that you can call methods on: https://dice-roller.github.io/documentation/guide/customisation.html#random-number-generator

So we'd have a class (e.g. Output that you can pass an engine or similar names object to, that handles the output itself.

The engine will have to have a public method (e.g. output()) that takes the object to output (and probably a context object, which could contain things like the parent, for contextual output / styling):

type ObjectTypes = RollResult | ResultGroup ...;

interface engine {
    output<ReturnType>: (arg: ObjectTypes, context: { parent?: ObjectTypes | undefined }) => <ReturnType>
}
  • Each object that can be output will need an output() method. When called, it calls a method on the Output class which in turn calls the output() method on the current output engine - passing in the object to output.
  • The engine then handles the output in whichever way is appropriate and returns the response however it likes.
  • This needs to handle opening / closing of output so we can do things like wrapping children in the HTML of a parent element. This might require a before() and after() method, or maybe wrap() which returns an array of two parts - start and end?
  • A default engine should be created that simply calls the toString() method on the object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant