Refactor to speedup resource implementation #13

Merged
antman merged 4 commits from try-with-children into resource-refactor 2026-08-17 08:38:39 +00:00
Owner

Motivation

There are 12 resource implementations to write and maintain, that we know of so far. We want to minimize code duplicated amongst them as this will incur obvious maintenance burden, and it was already getting difficult to keep things consistent with just 2 implementations. The boilerplate code was getting quiet tedious when writing resource implementations, and it's likely that there will be more resource types to implement.

Solution

I tried creating a higher order function that would take in another function that would be the resource creation function which the HOF would enhance. This turned out to be an inversion of what was required. Instead, the resource instance creation function (e.g. defineFileResource) calls a getImplementers function which takes a handful of arguments and returns a set of common properties and higher order functions that must wrap the CRUDD methods of a resource.

The downside of this approach is that anyone implementing a resource gets a little less guidance from the type system, but the upside is we don't have bidirectional data that they must flow between the higher order function and the concrete implementation, which gets very messy and confusing in a way outweighs the benefit of slightly better type hinting.

### Motivation There are 12 resource implementations to write and maintain, that we know of so far. We want to minimize code duplicated amongst them as this will incur obvious maintenance burden, and it was already getting difficult to keep things consistent with just 2 implementations. The boilerplate code was getting quiet tedious when writing resource implementations, and it's likely that there will be more resource types to implement. ### Solution I tried creating a higher order function that would take in another function that would be the resource creation function which the HOF would enhance. This turned out to be an inversion of what was required. Instead, the resource instance creation function (e.g. `defineFileResource`) calls a `getImplementers` function which takes a handful of arguments and returns a set of common properties and higher order functions that must wrap the CRUDD methods of a resource. The downside of this approach is that anyone implementing a resource gets a little less guidance from the type system, but the upside is we don't have bidirectional data that they must flow between the higher order function and the concrete implementation, which gets very messy and confusing in a way outweighs the benefit of slightly better type hinting.
it doesn't really work
Some checks failed
/ test-and-lint (push) Failing after 8s
37590fd143
Added getImplementers
Some checks failed
/ test-and-lint (push) Failing after 7s
7c8358d6c2
Reinstate important comment
Some checks failed
/ test-and-lint (push) Failing after 7s
1e304377a2
Reinstate parent.registerChild
Some checks failed
/ test-and-lint (push) Failing after 4m31s
f7f2eb4306
antman merged commit d5c9b3dbf3 into resource-refactor 2026-08-17 08:38:39 +00:00
antman deleted branch try-with-children 2026-08-17 08:38:39 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
kill-the-cloud/server-manager!13
No description provided.