drozdzynski

drozdzynski

Storex is a frontend store with state management handled on the backend. It allows you to update the store state both from the frontend and backend, with all communication occurring over WebSocket.

More info available on Github.

Why Storex?

Features

  • Efficient state management: Only the differences (diffs) in the store state are sent with each mutation, minimizing data transfer.

  • Real-time updates: State changes are immediately reflected across all connected clients via WebSocket communication.

  • Backend-driven state: Storex allows both the frontend and backend to update the store state seamlessly.

  • Lightweight and fast: Designed for minimal overhead, ensuring rapid state updates and communication.

Key Differences from Phoenix LiveView

Phoenix LiveView is a powerful tool for building rich, interactive web applications without writing custom JavaScript. However, as your application grows, managing complex client-side state across multiple LiveViews or components can become challenging. This is where Storex comes in.

  • Client-Side State Management: While Phoenix LiveView handles server-side rendering and event handling, Storex focuses on managing state on the client side. It allows you to keep your client-side state in sync with the server, but with more flexibility in how that state is stored, updated, and accessed.

  • Decoupled State Logic: Storex decouples state management from the LiveView itself, enabling you to manage state across multiple components or even across the entire application. This contrasts with LiveView, where state is typically tied to a specific LiveView process.

  • Predictable State Updates: Storex follows a predictable, unidirectional data flow similar to Redux. This makes it easier to reason about state changes and debug issues, especially in complex applications.

  • Extensibility: Storex is designed to be highly extensible, allowing you to integrate it with other tools and libraries in the Elixir ecosystem. You can also define custom middleware to handle side effects, logging, or other tasks.

For an overview of Storex in action, check out the example provided here.

Showing Posts 1 to 10

drozdzynski

drozdzynski OP

Hello,

I want to announce that stex was renamed to storex and published to hex.pm with version 0.1.0.

Changelog:

  • The only diff of the store state is being sent on each mutation.
  • Subscriber of connection status
  • Fixes in library

Links:

drozdzynski

drozdzynski OP

Version 0.2.0 released

Changelog:

  • Dynamic registry declaration
    • Default registry on ETS
  • Fix issue with a restart of Store when stopped on disconnect
  • Update dependencies
al2o3cr

al2o3cr

@drozdzynski FYI, I noticed the title of the thread was out-of-sync with the new name and adjusted it.

drozdzynski

drozdzynski OP

Version 0.2.2 released

Changelog:

  • Typescript/Javascript improvements
  • Fix reconnect of WebSocket on connection close

Version 0.2.3 released

Changelog:

  • Fix reconnect of WebSocket on connection close
Sebb

Sebb

That’s interesting.
Do you think it would be feasible to add fw-specific wrappers around Storex, so that we could (for example) use a SolidJS store transparently?

So (in this case) Solid’s reactive system could create an event, which is (maybe) processed in the backend (without any further ado) which then modifies the store which then leads to a reaction (without further ado) on the client side…?

drozdzynski

drozdzynski OP

I designed it as a replacement for frontend stores.
If you want to use it with SolidJS you can use from function to display the current state.

Example:

import { render } from "solid-js/web";
import { from } from "solid-js";
import Storex from "storex";

const store = new Storex({
  store: "App.RandomNumber",
  params: {},
});

function RandomNumber() {
  const state = from(store);

  return (
    <button onClick={() => store.commit("change", Math.random())}>
      {state()}
    </button>
  );
}

render(() => <RandomNumber />, document.getElementById("app")!);
Sebb

Sebb

Thats very nice. So Storex on the client side acts as an observable (implementing subscribe)…?

I’ve only played a little with SolidJS, so I can’t say if there are any drawbacks (besides having to “learn” the Storex API for writing). If it works as I think (have to try it out) this just rocks. Liveview is really great, but I’ve a project now, that is so dynamic that I need a frontend framework. This could bring one of the biggest benefits of LV - removing all the layers between backend and frontend - to any (reactive?) framework (implementing sth like from)

drozdzynski

drozdzynski OP

Yes, storex has the subscribe method in Store to work with reactivity.
I’m using storex with svelte frontend framework which works on subscribe method on reactivity.

Example:

<script lang="ts">
  import Storex from 'storex'
  
  const store = new Storex<RandomNumber>({
    store: 'App.RandomNumber',
    params: {},
  })
</script>
{#if $store}
  Random number: {$store}
{/if}
Sebb

Sebb

I finally had the time to check this out. Looks very promising.

Some things I noticed (I have very limited JS-skills, so may be bullshit)

  • In your “connect to store” example, I replaced const with var here: subscribe: (state) => {var state = state} (does not work otherwise)
  • your example uses an integer as state, which did not work for me. Changed to a map.
  • storex depends on Jason, which is not installed with deps.

I created a sample app. Especially the websocket handling is not obvious, I used GitHub - kevinlang/plug_socket: Add Cowboy websockets to your Plug.Router easily. · GitHub which makes that easy.

Sample app: GitHub - georgfaust/storex_example_app: solidjs examples for https://github.com/nerdslabs/storex · GitHub

drozdzynski

drozdzynski OP

In your “connect to store” example, I replaced const with var here: subscribe: (state) => {var state = state} (does not work otherwise)

You are right, it’s my mistake, I will update README

your example uses an integer as state, which did not work for me. Changed to a map.

I tested that as well and it’s a bug, thanks for catching that

storex depends on Jason, which is not installed with deps.

I will fix it with this integer as a state

Where Next? Top

Trending in Announcing Top

woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
ahamez
Hi everyone, I’ve been working on this protobuf library for 3 years. We use it in the company I work for, EasyMile, to communicate with ...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews