Skip to content

Add an alternate mode for qlkit parsing that doesn't clobber global state #4

@drcode

Description

@drcode

When we call code such as:

(ql/mount {:parsers {:read   pa/read
                                  :mutate pa/mutate}})

It sets a global singleton- This is fine in most use cases, but it would be great to have an alternate mount command that looks something like: (but hopefully something less wordy)

(ql/mount {:parsers {:read   pa/read
                                  :mutate pa/mutate}
                  :preserve-global-environment true})

If this version of the command is used, the parser functions and (optional) state atom are passed using the environmental variable, and need to be referenced by parsers by pulling them out of the environmental variable. Parsing functions may become a bit more complex to write, which is the tradeoff. Also, the environment variable is no longer printable, as it now isn't merely an EDN data structure.

The potential benefits of this feature are:

  • You could mount multiple qlkit nodes in the browser (for "devcards" type stuff, perhaps)
  • You can run unit tests in parallel on the server (because they won't step on each other's toes by overwriting the singleton parser information)
  • Repl actions can be performed without clobbering app state
  • Independent qlkit endpoints can exist in a single server process

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions