Skip to content

Conversation

@rtyley
Copy link
Member

@rtyley rtyley commented Dec 2, 2025

This is a tweaked version of the work done in #28417 (so see the functionality description there!), but built upon the refactors done in #28437, which allows this implementation to be a bit smaller.

Changes relative to the original PR #28417

In LiveHarnessController.renderLiveHarness():

In LiveHarness:

  • The important code in turnLocalAtomsIntoAtomBlocksAndElements() - that makes an InteractiveAtom or BlockElement out of a LiveHarnessInteractiveAtom - has moved onto LiveHarnessInteractiveAtom itself (so all the references copying data from localAtom.xxx fields become just references to xxx field itself)
  • A fiddly bit of functionality - updating the content within a ContentPage, which varies depending on whether it's a ArticlePage or InteractivePage - has been isolated into a PageUpdater type class. This allows us to have much clearer code elsewhere - without having to define a content-updating method for every single ContentPage type, just the two we care about. Consequently, there's not a need for either of the two injectInteractiveAtomsIntoPage() methods that used to exist - just a single inject() method, which does the work of addLocalAtomsToParent() too.
  • We use the handy splitAt() method to make a bit of code in addLocalAtomsToParent() a bit smaller.

In InteractiveController:

@rtyley rtyley force-pushed the refactor-prior-to-live-harness branch from 9e78e21 to c413902 Compare December 2, 2025 11:27
@rtyley rtyley force-pushed the live-harness-endpoint-refactor branch from a920d3f to 8650909 Compare December 2, 2025 11:27
@github-actions
Copy link
Contributor

github-actions bot commented Dec 2, 2025

@rtyley rtyley marked this pull request as ready for review December 2, 2025 15:50
@rtyley rtyley requested a review from a team as a code owner December 2, 2025 15:50
@frederickobrien frederickobrien self-assigned this Dec 2, 2025
@frederickobrien frederickobrien added the feature Departmental tracking: work on a new feature label Dec 2, 2025
@frederickobrien frederickobrien added this to the Visuals milestone Dec 2, 2025
Base automatically changed from refactor-prior-to-live-harness to main December 5, 2025 10:06
This is a tweaked version of the work done in #28417,
but built upon the refactors done in #28437, which
allows this implementation to be smaller.

In `LiveHarnessController.renderLiveHarness()`:

* The `ArticleController.mapAndRender()` & `InteractiveController.modelAndRender()`
  methods introduced in #28437 are useful not only within those controllers, but also
  more suitable for the work needed in `renderLiveHarness()`, meaning that each case
  (`ContentType.Article` & `ContentType.Interactive`) can be handled much more concisely -
  a single line each.
* We can avoid transforming the `JsResult` to an `Either`, and just match on
  `JsSuccess`/`JsError` rather than `Right`/`Left`
* The `match` statement on the `Option[ContentType]` can be done slightly more concisely
  using `collect` : https://www.scala-lang.org/api/2.13.18/scala/Option.html#collect[B](pf:PartialFunction[A,B]):Option[B]

In `LiveHarness`:

* The important code in `turnLocalAtomsIntoAtomBlocksAndElements()` - that makes an
  `InteractiveAtom` or `BlockElement` out of a `LiveHarnessInteractiveAtom` - has moved
  onto `LiveHarnessInteractiveAtom` itself (so all the references copying data from
  `localAtom.xxx` fields become just references to `xxx` field itself)
* A fiddly bit of functionality - updating the `content` within a `ContentPage`, which
  varies depending on whether it's a `ArticlePage` or `InteractivePage` - has been isolated
  into a `PageUpdater` type class. This allows us to have much clearer code elsewhere -
  without having to define a content-updating method for every single `ContentPage` type,
  just the two we care about. Consequently, there's not a need for either of the two
  `injectInteractiveAtomsIntoPage()` methods that used to exist - just a single `inject()`
  method, which does the work of `addLocalAtomsToParent()` too.
* We use the handy `splitAt()` method to make a bit of code in `addLocalAtomsToParent()` a
  bit smaller.

In `InteractiveController`:

* A small new `modelAndRenderHtml()` method is required, to match the behaviour from #28417
  which short-circuits a lot of logic to ensure that `renderHtml()` is called.

Co-Authored-By: Jonathon Herbert <[email protected]>
Co-Authored-By: Frederick O'Brien <[email protected]>
@frederickobrien frederickobrien force-pushed the live-harness-endpoint-refactor branch from 8650909 to 52c4785 Compare December 5, 2025 10:17
@frederickobrien frederickobrien merged commit c28d1ac into main Dec 5, 2025
9 checks passed
@frederickobrien frederickobrien deleted the live-harness-endpoint-refactor branch December 5, 2025 13:28
@gu-prout
Copy link

gu-prout bot commented Dec 5, 2025

Seen on ADMIN-PROD (created by @rtyley and merged by @frederickobrien 7 minutes and 56 seconds ago)

@gu-prout
Copy link

gu-prout bot commented Dec 5, 2025

Seen on FRONTS-PROD (created by @rtyley and merged by @frederickobrien 10 minutes and 9 seconds ago)

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

Labels

feature Departmental tracking: work on a new feature Seen-on-ADMIN-PROD Seen-on-FRONTS-PROD

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants