Skip to content

Instantly share code, notes, and snippets.

@asfktz
asfktz / Effect Layers - Moving Dependencies from Service to Effect Execution.md
Last active July 20, 2025 22:18
Effect Layers: Moving Dependencies from Service to Effect Execution

Effect Layers: Moving Dependencies from Service to Effect Execution

The Problem: Service Dependencies vs Program Dependencies

When designing Effect services, there's a critical distinction between what the service needs to exist versus what the program needs to execute. This distinction determines whether your services can be managed at the runtime level or need to be recreated for each execution.

Before: Service-Level Dependency

export class UserSrv extends Effect.Service<UserSrv>()("UserSrv", {
@asfktz
asfktz / TUTORIAL_LAYERS_AND_RUNTIME.md
Last active July 20, 2025 22:16
Effect Tutorial: Preventing Layer Recreation Per Request - Singleton Runtime Pattern

TODO: Remove the incorrect parts.
See: https://gist.github.com/asfktz/49e2ca5030cb60be83da5386a6c07bbf2 for more recent insights.

Preventing Layer Recreation Per Request in Effect

Introduction

This tutorial demonstrates how to prevent recreating layers on every request by using a singleton managed runtime with Effect while still allowing dynamic, per-request dependencies. The main problem this solves is avoiding the wasteful recreation of the same layers repeatedly.

1. Setting Up Context Tags

@asfktz
asfktz / Tabs.jsx
Last active November 23, 2019 11:19
Context Based Tabs
import React, { Children, cloneElement, useState, createContext, useContext } from 'react';
const ctx = createContext();
export function Tabs ({ children }) {
const [selectedIndex, selectIndex] = useState(0);
return (
<ctx.Provider value={{ selectedIndex, selectIndex }}>
{children}
import './style.css';
import React, { useState } from 'react';
import Spinner from 'react-md-spinner';
import useInterval from '../../utils/useInterval';
import { random } from 'lodash';
const labels = [
'מכוונים את הגיטרות',
'פורשים מחצלות',
const MyWrapperMiddleware = store => next => action => {
const state = store.getState()
if (!state.isLoggedIn)
return next(action)
const pouchMiddleware = PouchMiddleware({
path: state.currentPath,
db,
let pouchMiddleware
let invalidate = true;
const MyWrapperMiddleware = store => next => action => {
const state = store.getState()
if (!state.isLoggedIn)
return next(action)
if (someConditionForChange) {
@asfktz
asfktz / UserForm.jsx
Last active February 10, 2017 23:11
react-redux-form nested reducer issue
import React from 'react';
import { Control, Form } from 'react-redux-form';
class UserForm extends React.Component {
render() {
return (
<Form model="forms.user"
onSubmit={(user) =>
console.log('-->', user)
}>
class Button extends React.Component {
handleClick = (e) => {
console.log(this)
}
render () {
return (
<div onClick={this.handleClick}>
Click
</div>
class Button extends React.Component {
constructor (props) {
super(props)
this.handleClick = this.handleClick.bind(this)
}
handleClick () {
console.log(this)
}
class Button extends React.Component {
handleClick () {
console.log(this)
}
render () {
return (
<div onClick={::this.handleClick}>
Click
</div>