Skip to main content

๐Ÿง  What is a Dynamics System?

jods mascots and the dynamics system

๐Ÿ”„ Beyond Traditional State Managementโ€‹

A Dynamics System represents a significant evolution in how we think about state management in JavaScript applications. Unlike traditional state management solutions that focus solely on storing and updating values, a Dynamics System creates a living, responsive ecosystem where objects intuitively react to changes, compute derived values, and maintain consistency across your application.

๐Ÿ’ก The jods Philosophyโ€‹

jods (JavaScript Object Dynamics System) takes a fundamentally different approach than other state libraries. Rather than requiring you to learn complex patterns, middlewares, or actions/reducers, jods embraces the natural way developers already work with JavaScript objects.

At its core, a Dynamics System:

  1. ๐Ÿ“ฑ Feels Natural: Uses direct mutations (user.name = "Burt") instead of verbose action dispatchers
  2. ๐Ÿ”„ Reacts Intelligently: Automatically tracks dependencies and triggers updates
  3. ๐Ÿงฎ Computes Effortlessly: Handles derived values through simple function declarations
  4. ๐Ÿ“ท Snapshots Seamlessly: Creates consistent, serializable snapshots of application state
  5. ๐Ÿงฌ Bridges Environments: Works the same way on client, server, or any JavaScript environment

๐Ÿ” How is a Dynamics System Different?โ€‹

Let's compare jods with some other popular approaches:

FEATURETRADITIONAL OBJECTREDUXZUSTANDJODS (DYNAMICS SYSTEM)
Updating stateobj.name = "Burt"dispatch(setName("Burt"))setState({name: "Burt"})user.name = "Burt"
ReactivityNoneManual subscriptionsSelector functionsAutomatic + granular
Computed valuesManual functionsSelector functionsSelector functionscomputed(() => user.firstName + " " + user.lastName)
SerializationJSON.stringify(obj)Need custom serializersNeed custom serializersjson(user)
Framework integrationNoneRequires connectorsHooksLightweight direct hooks

โšก The Power of Dynamics: Code Examplesโ€‹

Let's see how a Dynamics System makes development more intuitive:

import { store, computed, onUpdate, json, diff } from "jods";

// Create a reactive store
const user = store({
firstName: "Burt",
lastName: "Macklin",
age: 36,
department: "FBI",
});

// Add a computed property - recalculates only when dependencies change
user.fullName = computed(() => `${user.firstName} ${user.lastName}`);

// Subscribe to changes with both new and old state
onUpdate(user, (newState, oldState) => {
console.log("Previous state:", json(oldState));
console.log("Current state:", json(newState));

// Agent Macklin investigates the changes with diff()
const changes = diff(oldState, newState);
console.log("Agent Macklin's case file:", changes);
console.log(
"Macklin: 'I've identified all the changes. Just as I suspected!'"
);
});
// Make changes directly - feels like regular JavaScript!
user.firstName = "FBI Agent";
// Logs:
// Previous state: {
// firstName: 'Burt',
// lastName: 'Macklin',
// age: 36,
// department: 'FBI',
// fullName: 'Burt Macklin'
// }
// Current state: {
// firstName: 'FBI Agent',
// lastName: 'Macklin',
// age: 36,
// department: 'FBI',
// fullName: 'FBI Agent Macklin'
// }
// Agent Macklin's case file: {
// firstName: { from: 'Burt', to: 'FBI Agent' },
// fullName: { from: 'Burt Macklin', to: 'FBI Agent Macklin' }
// }
// Macklin: 'I've identified all the changes. Just as I suspected!'

// Multiple properties can be changed in a single update
Object.assign(user, {
lastName: "Macklin Jr.",
age: 37,
department: "Special Agent Division",
});
// The diff() will show all changes at once, and computed properties update automatically

๐Ÿฆ‹ Dynamic Adaptabilityโ€‹

A key aspect of a Dynamics System is its ability to adapt to how developers and AI work together ๐Ÿง‘โ€๐Ÿ’ป๐Ÿค–. As AI becomes increasingly important for code generation and maintenance, jods provides a model that:

  1. ๐Ÿค– Works with AI coding: Predictable patterns make it easy for AI tools to understand and modify
  2. ๐Ÿ“ Requires minimal boilerplate: Focus on business logic, not plumbing
  3. โšก Integrates anywhere: Works with React, Preact, Remix, or vanilla JS
  4. ๐Ÿ” Makes debugging easy: Time-travel debugging with history(store)
  5. ๐Ÿงฉ Composes naturally: Build complex state by combining simple pieces

๐Ÿ—๏ธ Dynamics in a Full-Stack Contextโ€‹

In a full-stack application, particularly with frameworks like Remix, a Dynamics System serves as the perfect bridge between server and client state:

// Define a model once with jods/remix
export const todoStore = defineStore({
name: "todos",
schema: z.object({
items: z.array(
z.object({
id: z.string(),
text: z.string(),
completed: z.boolean(),
})
),
filter: z.enum(["all", "active", "completed"]),
}),
// Server-side handler
handlers: {
async addTodo({ current, form }) {
return {
...current,
items: [
...current.items,
{
id: crypto.randomUUID(),
text: form.get("text"),
completed: false,
},
],
};
},
},
});

// Use in component with the same simple API
function TodoApp() {
const todos = useJodsStore(todoStore);
const form = useJodsForm(todoStore.actions.addTodo);

return (
<div>
<form {...form.props}>
<input name="text" />
<button type="submit">Add</button>
</form>
<ul>
{todos.items.map((item) => (
<li key={item.id}>
<input
type="checkbox"
checked={item.completed}
onChange={() => (item.completed = !item.completed)}
/>
{item.text}
</li>
))}
</ul>
</div>
);
}

๐Ÿค Why "Dynamics" Matters for AI Collaboration ๐Ÿค– ๐Ÿง โ€‹

In the age of AI-assisted coding, the Dynamics System approach unlocks new possibilities. When you and AI tools collaborate on code, jods provides a mental model that:

  • ๐Ÿ—ฃ๏ธ Is easy to explain to AI ("update this state directly")
  • ๐Ÿ’ป Is easy for AI to generate correct code for
  • ๐Ÿ“‰ Minimizes boilerplate that AI has to generate
  • ๐Ÿ”„ Provides consistent patterns that AI can understand and maintain
  • ๐Ÿงฉ Allows AI to focus on business logic, not state plumbing

๐ŸŒŸ A living model of your applicationโ€‹

A Dynamics System is more than just a state container - it's a living model of your application that reacts, computes, and synchronizes automatically. By embracing the natural way JavaScript works while adding reactivity and computed values, jods creates a development experience that is both simpler and more powerful.

The days of complex state management are coming to an end. ๐ŸŽฌ

๐Ÿ‘‹ Welcome to the era of Dynamics Systems, where your objects come alive. ๐Ÿฟ๏ธ ๐Ÿฆ†