How migueldelmazo/wu works
Project type and purpose
• This is a JavaScript framework library (usable in browser or Node.js), not a deployed application. Its goal is to provide a reactive data model and a declarative API (ensurer, watcher, getter, setter, router, api) for building web apps.
• The README confirms this: it’s a proof-of-concept framework in beta, focused on model consistency and functional programming.
File structure
• Top-level directories:
• src/ – all core modules
• docs/ – user documentation
• resources/ – static assets (logo)
• src/tests/ – unit tests
• Core files in src/:
• Core orchestration: index.js, definition.js, common.js, model.js
• Item implementations:
– ensurer.js
– watcher.js
– getter.js
– setter.js
– router.js
– api.js plus related submodules (api-cache.js, api-queue.js, api-flags.js, api-online.js, api-handlers.js)
• Utility: lodash.js (embedded dependency)
Key insights from README
• Reactive Data Model (wu.model): central “state store” with watchable paths.
• Declarative Items: 6 types, each defined via wu.create(type, name, props).
• Event‐Driven Flow: changes in model → trigger ensurers, watchers, api, router → those may update model again or call externals.
• Public API: wu.create(), wu.start(), wu.getter(), wu.setter(), plus wu.model.*.
Main components & interactions
1. Public API Layer (exposed to app code)
• wu.create(), wu.start(), wu.getter(), wu.setter(), wu.model.{get,set,watch,stopWatching,populate}
2. Definition & Bootstrapping
• definition.js – reads create() calls, registers items
• index.js – initialises the model, starts the watcher loop
3. Core Reactive Data Model
• model.js – in-memory store, path-based getter/setter, event bus for onChange
4. Item Handlers
• Ensurer (ensurer.js)
• Watcher (watcher.js)
• Getter (getter.js)
• Setter (setter.js)
• Router (router.js)
• API (api.js + api-cache, api-queue, api-flags, api-online, api-handlers)
5. Utilities
• common.js – shared helper functions
• lodash.js – third-party util functions
6. External Environment
• Browser/Node runtime
• HTTP endpoints (API server)
• Third‐party libraries (e.g. React via watcher)
b. Relationships & data flow
• App code calls wu.create() → registers item in Definition
• Model emits “change” events when wu.model.set() is invoked
• Item Handler subscribes to model paths (onChange):
• Ensurer/getter/setter/router/api/watchers all register callbacks
• When triggered:
• Ensurer runs pure function → calls model.set(updatePath)
• Watcher runs impure function → calls external API or DOM/React
• Getter defines read-only function for app to call (wu.getter())
• Setter accepts app input, runs pure function → model.set(updatePath)
• Router listens to URL changes, updates model
• API pipeline: onChange → request (via api-handlers) → queue/cache → network → response → model.set() on success or error
• The cycle may repeat if those model.set() calls trigger other items.
c. Architectural patterns & principles
• Observer pattern: model as subject, items as observers
• Functional/reactive style: pure functions except watchers, single source of truth
• Modular design: 1 file per item, clear separation of concerns
• Declarative registration: users declare items, framework wires them up
d. Key technologies
• Vanilla JS (ES6 modules), no runtime dependencies except Lodash
Final advice
• How the reactive loop works: model change → triggers → model change → …