Skip to content

Instantly share code, notes, and snippets.

@pixelprodev
pixelprodev / gist:190b6b9fa16b443e9c1668ad65003f45
Last active April 11, 2025 17:08
Domain Object Style state management using @preact/signals-react and React 19

I'll preface this by saying I have a LOT of freedom in the app that I'm currently working on, and I've taken that liberty to push the envelope of curiosities. I recently read about signals (specifically @preact/signal-react) and it got me to thinking. This is the brainchild first iteration of this. I am posting this with hopes that one of two things happen. I hope first and foremost that I can learn from someone in some way here. If I'm short-sighted or missing something, point it out, please. I've been coding for years but still feel brand new and still make a lot of mistakes. If it helps someone else learn something, well that's ok too.

Conceptually, I build my domain objects using a building block class that I call a "ReactiveMap". Feel free to swap this out for any type of implementation you want to use for your domain model's base, but this works for my particular use case.

The ReactiveMap mimics the api of a javascript Map object with some utility additions, and adds the ability for you to

@pixelprodev
pixelprodev / wallaby.config.js
Created August 27, 2017 04:07
wallaby config
module.exports = function (wallaby) {
return {
files: [
{pattern: 'src/**/*.js'},
{pattern: 'src/**/*.jsx'},
{pattern: 'src/**/*.spec.js', ignore: true},
{pattern: 'src/**/*.json', instrument: false}
],
tests: [
@pixelprodev
pixelprodev / store.js
Created May 19, 2017 21:26
same output
export function generateStore ({mode = (process.env.NODE_ENV || 'test'), injectedState = {}}) {
return mode === 'development'
? createStore(reducers, injectedState, composeWithDevTools(applyMiddleware(sagaMiddleware)))
: createStore(reducers, injectedState, applyMiddleware(sagaMiddleware))
}
@pixelprodev
pixelprodev / index.js
Created May 13, 2017 22:27
Example store index file
import { applyMiddleware, createStore, combineReducers } from 'redux'
import { composeWithDevTools } from 'redux-devtools-extension'
import AccountReducer from './reducers/account'
import AppReducer from './reducers/app'
import BusinessUnitReducer from './reducers/businessUnit'
import createSagaMiddleware from 'redux-saga'
import LicenseReducer from './reducers/license'
import PackageReducer from './reducers/package'
import PromptReducer from './reducers/prompt'
import ProvisionReducer from './reducers/provision'
mongoose.connect('connection string here') // <-- this saves to the singleton. your callback to confirm is fine if you just want to know that it connected for sure. :+1:
//now that mongoose is connected, you need a model in order to save a document
//schemas use json validator syntax so type declaration is Number, String, Bolean, etc (native js types)
const userSchema = mongoose.Schema({
name: String
})
const userModel = new mongoose.model('user', userSchema)