alloc/saus

Auto-generated barrel for state modules

Closed this issue · 2 comments

It's common to keep all state modules in the same folder. What if we could take advantage of that by generating a module that re-exports all state modules (aka: a barrel), but also unwraps them so client modules don't have to use .get anymore. 🤩

// Generated code
import { foo as _foo } from './foo'
export const foo = _foo.get()

We can even generate the barrel slightly different when loading the routes module, since it works with StateModule objects, not the raw values. The only issue here is that we may not be able to use different typings based on who imports the barrel. 🤔

Another option is to recommend keeping your state modules in an entirely separate package, away from your application code. Then we can generate entry points, one for node, one for client.

For example, if I keep my state modules in a package called @app/state, then I could import the StateModule objects from a generated barrel via import {...} from "@app/state/node" and I could import their raw values from another generated barrel via this import {...} from "@app/state" statement.

Closing in favor of #52