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

Add dynamic instantiation contexts #26

Open
dfrese opened this issue Feb 25, 2019 · 0 comments
Open

Add dynamic instantiation contexts #26

dfrese opened this issue Feb 25, 2019 · 0 comments

Comments

@dfrese
Copy link
Member

dfrese commented Feb 25, 2019

I would like the see the introduction of a dynamic instantiation context for classes, i.e. given an 'opt' value and an 'app-state' value in a context, then instantiating classes should require only the declared parameters of the class:

(with-instantiation-context {:reaction ... :app-state ...}
  (my-class arg1 arg2))

which should be implemented via a ':dynamic' binding, and be equivalent to

(my-class (reacl/opt :reaction ...) app-state arg1 arg2)

This would have the following advantages:

  • The arguments to a 'class call' would be syntactically exactly those listed as the 'params' in the class definition; which it easier to read and understand.
  • Abstractions over classes could be simple functions, without the need for a complicated optional 'opt' (and app-state) argument, or even a whole new class. It would bring classes and abstractions over classes on the 'same level', where they are currently very far apart.
  • :reaction (or esp. :embed-app-state clauses) and the current app-state value would move closer together. They are usually highly interdependent anyway - one has to think about and change both at the same time.
  • Also, esp. the 'opt' declaration is conceptionally nothing that is 'passed' to the class implementation; i.e. it does not have access to it, although it is currently an argument to it. Writing it 'outside' of the class instantiation is much more natural (to me).
  • It would enable reusable abstractions over contexts; some may make it easier to prevent the mistake of passing and updating a state differently; some may allow consistent modification of contexts ('append' lenses; map over actions etc).
  • Together, this allows for much easier composition of dom elements and classes, as the dom composition and the state composition can be defined in two steps.

This could be added backwards-compatible, if the instantiation function of classes falls back to the current mode, if there is no context set. That legacy mode could be turned off later (or on request per class), to allow for better error messages. Another future option would be to have an implicit default context in the render function; maybe as an opt-in for each class to remain backwards compatible.

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

No branches or pull requests

1 participant