ReArch = re-imagined approach to application design and architecture
We must state definitions and provide for priorities and descriptions of data. We must state relationships, not procedures.
-- Grace Murray Hopper, Management and the Computer of the Future (1962)
Specifically, ReArch is a novel solution to:
- ⚡️ State Management
- 🧮 Incremental Computation
- 🧱 Component-Based Software Engineering
And with those, come:
- Reactivity through declarative code
- Loose coupling and high testability
- App-level composability via a functional approach to dependency inversion
- Feature composition through side effects
Define your "capsules" (en-capsulated pieces of state) at the top level:
// Capsules are simply functions that consume a CapsuleHandle.
// The CapsuleHandle lets you get the data of other capsules,
// in addition to using a large variety of side effects.
// This particular capsule manages a count from a classic example counter app,
// using the state side effect.
(int, void Function()) countManager(CapsuleHandle use) {
final (count, setCount) = use.state(0);
return (count, () => setCount(count + 1));
}
// This capsule provides the current count, plus one.
int countPlusOneCapsule(CapsuleHandle use) => use(countManager).$1 + 1;// Capsules are simply functions that consume a CapsuleHandle.
// The CapsuleHandle lets you get the data of other capsules,
// in addition to using a large variety of side effects.
// This capsule provides a count and a way to increment that count.
fn count_manager(CapsuleHandle { register, .. }: CapsuleHandle) -> (u8, impl CData + Fn()) {
let (count, set_count) = register(effects::state::<Cloned<_>>(0));
let increment_count = move || set_count(count + 1);
(count, increment_count)
}
// This capsule provides the count, plus one.
fn count_plus_one_capsule(CapsuleHandle { mut get, .. }: CapsuleHandle) -> u8 {
let (count, _increment_count) = get(count_manager);
count + 1
}