From d3fbb6b7d354a943af3a6756c184967a3f6cfece Mon Sep 17 00:00:00 2001 From: pravintargaryen <96950453+pravintargaryen@users.noreply.github.com> Date: Sun, 21 Dec 2025 11:38:10 +0530 Subject: [PATCH 1/2] Document Observable Store integration with Solid.js Added instructions for using Observable Store with Solid.js, including creating a Solid.js app, a customer store, and accessing the store in a Customers component. --- README.md | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/README.md b/README.md index c07d1394..d176bf74 100644 --- a/README.md +++ b/README.md @@ -544,6 +544,124 @@ See the `samples` folder in the Github repo for examples of using Observable Sto } ``` +## Using Observable Store with Solid.js + +1. Create a Solid.js App with Typescript using Vite + +``` +npm create vite@latest +``` + +2. Create a Customer Store + +``` typescript +// stores/CustomersStore.ts +import { ObservableStore } from '@codewithdan/observable-store'; + +export class CustomersStore extends ObservableStore { + constructor() { + super({ trackStateHistory: true }); + } + + fetchCustomers() { + const customers = [ + { + id: 1, + name: 'Jane Doe', + address: { + street: '123 Main St', + city: 'Phoenix', + state: 'AZ', + zip: '85258' + } + }, + { + id: 2, + name: 'John Smith', + address: { + street: '456 Oak Ave', + city: 'Austin', + state: 'TX', + zip: '73301' + } + }, + { + id: 3, + name: 'Pravin', + address: { + street: '456 Oak Ave', + city: 'Austin', + state: 'TX', + zip: '73301' + } + } + ]; + + this.setState({ customers }, 'GET_CUSTOMERS'); + return Promise.resolve(customers); + } + + getCustomers() { + const state = this.getState(); + if (state?.customers) { + return Promise.resolve(state.customers); + } + return this.fetchCustomers(); + } + + getCustomer(id: number) { + return this.getCustomers().then(custs => { + const customer = custs.find(c => c.id === id) ?? null; + this.setState({ customer }, 'GET_CUSTOMER'); + return customer; + }); + } +} + +export default new CustomersStore(); +``` +3. Access the store in Customers Component + +``` typescript +// Customers.tsx +import { createSignal, onMount, onCleanup } from 'solid-js'; +import CustomersStore from '../stores/CustomersStore'; + +export default function Customers() { + const [customers, setCustomers] = createSignal([]); + + let storeSub: any; + + onMount(() => { + // Option 1: subscribe to store changes + storeSub = CustomersStore.stateChanged.subscribe(state => { + if (state?.customers) { + setCustomers(state.customers); + } + }); + + // Trigger data load + CustomersStore.getCustomers(); + }); + + onCleanup(() => { + storeSub?.unsubscribe(); + }); + + return ( +
+

Customers

+ +
+ ); +} + +``` + ### Using Observable Store with Vue.js .... From 4ccaf039695394163529619e2e087abde6b6d343 Mon Sep 17 00:00:00 2001 From: pravintargaryen <96950453+pravintargaryen@users.noreply.github.com> Date: Sun, 21 Dec 2025 11:41:09 +0530 Subject: [PATCH 2/2] Add SolidJS sample application to README --- README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d176bf74..1641cff8 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,7 @@ Open the `samples` folder available at the Github repo and follow the instructio * [Using Observable Store with Angular](#angular) * [Using Observable Store with React](#react) +* [Using Observable Store with SolidJS](#solid) * [Using Observable Store with Vue.js](#vue) ## Using Observable Store with Angular @@ -544,15 +545,22 @@ See the `samples` folder in the Github repo for examples of using Observable Sto } ``` -## Using Observable Store with Solid.js +## Using Observable Store with SolidJS 1. Create a Solid.js App with Typescript using Vite ``` npm create vite@latest ``` +2. Install `@codewithdan/observable-store`: -2. Create a Customer Store + `npm install @codewithdan/observable-store` + +3. Install RxJS (a required peer dependency): + + `npm install rxjs` + +4. Create a Customer Store ``` typescript // stores/CustomersStore.ts @@ -620,7 +628,7 @@ export class CustomersStore extends ObservableStore { export default new CustomersStore(); ``` -3. Access the store in Customers Component +5. Access the store in Customers Component ``` typescript // Customers.tsx