Skip to content

Instantly share code, notes, and snippets.

@dfkaye
Last active June 30, 2021 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dfkaye/7ecc5758a65bf31e66fa5750012dc989 to your computer and use it in GitHub Desktop.
Save dfkaye/7ecc5758a65bf31e66fa5750012dc989 to your computer and use it in GitHub Desktop.
JQuery has all we need to make it reactive, if we add these four things.

Reactive JQuery

28 January 2021

Prior art by Meredith Matthews (July 2020), at https://css-tricks.com/reactive-jquery-for-spaghetti-fied-legacy-codebases-or-when-you-cant-have-nice-things/.

Turns out JQuery has almost everything we need to make it reactive (render-on-change-to-data). The virtual DOM is unnecessary if we have guards against unnecessary rendering. We don't need JSX to make it all look more like HTML templates.

This is heresy and not well thought out yet. Certain projects may do this already. None, I would bet serious Gamestop options, uses the SAM pattern.

JQuery has...

JQuery reactive

Small list of missing pieces.

  • $.diff(data): return a path-map of differences between the current data and the new data
  • $.next({ name, data }): fire an event of type name as a notifier to other registered listeners except on the current node.
  • $.on("render"): register a render-data change handler on the current node
  • $.render(data): pass data to the current node - internally calls diff() - if there's a diff, the current node's on("render") callback runs

Descendant drilling is tight coupling

Renders should occur only on the current node and NOT on the children or descendants. These "components" should be defined explicitly and not merely assumed or "passed in."

That's it.

Update March 1, 2021

Looks like JSViews has some of these ideas already.

However, the template DSL and one of its functions is susceptible to template string injections.

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