Skip to content

Instantly share code, notes, and snippets.

Avatar

Marius Andra mariusandra

View GitHub Profile
View githubLogicType.ts
// Auto-generated with kea-typegen. DO NOT EDIT!
export interface githubLogicType<Repository> {
key: undefined
actionCreators: {
setUsername: (
username: string,
) => {
type: 'set username (samples.githubLogic)'
payload: { username: string }
View kea-graphql.js
// This is a crude implementation of a graphql plugin for kea.
// It needs to be cleaned up, tested and then made into a real plugin.
// There is basic support for subscriptions and reloading.
// Mutations are not implemented
// To use:
// - logicWithGraphQL.values.course == { id: 123, { translations: [...] } }
// - logicWithGraphQL.values.courseVariables == { id: 123 }
import gql from 'graphql-tag'
import { kea } from 'kea'
View kea-devtools-alpha.js
import React, { useState } from 'react'
import { getContext } from 'kea'
function Connections ({ logic }) {
if (Object.keys(logic.connections).length === 1) {
return null
}
return (
<div style={{ marginTop: 10 }}>
@mariusandra
mariusandra / kea-dimensions.js
Last active May 21, 2020
dimensions plugin for kea
View kea-dimensions.js
import { setPluginContext, getPluginContext, useMountedLogic } from 'kea'
import { useEffect } from 'react'
/*
usage:
kea({
dimensions: {
// key: [defaultValue, calcFunction],
isSmallScreen: [false, window => window.innerWidth < 640],
View preloaded-state.js
// Plugin to make preloaded state work with kea 1.0
// (pseudocode, not tested, use )
{
name: 'preloadedState',
buildSteps: {
defaults (logic, input) {
const node = getContext().options.preloadedState
if (node) {
// find preLoadedState.[path[0]].[path[1]].etc
View routeset.txt
… actionpack-5.2.0/lib/action_dispatch/routing/route_set.rb:92:in `ActionDispatch::Routing::RouteSet::NamedRouteCollection#clear!' (99 samples - 6.40%) (2 exclusive - 0.13%)
/Users/marius/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/set.rb:336:in `Set#each' (118 samples - 7.63%)
… actionpack-5.2.0/lib/action_dispatch/routing/route_set.rb:92:in `ActionDispatch::Routing::RouteSet::NamedRouteCollection#clear!' (99 samples - 6.40%)
… actionpack-5.2.0/lib/action_dispatch/routing/route_set.rb:443:in `ActionDispatch::Routing::RouteSet#clear!' (100 samples - 6.47%)
… railties-5.2.0/lib/rails/application/routes_reloader.rb:49:in `Rails::Application::RoutesReloader#clear!' (100 samples - 6.47%)
… railties-5.2.0/lib/rails/application/routes_reloader.rb:49:in `Rails::Application::RoutesReloader#clear!' (100 samples - 6.47%)
… railties-5.2.0/lib/rails/application/routes_reloader.rb:18:in `Rails::Application::RoutesReloader#reload!' (1004 samples - 64.94%)
… railties-5.2.0/lib/rails/application/routes_reloader.rb:41:in `Rails::Ap
@mariusandra
mariusandra / slow-rails-reload-development.md
Last active May 15, 2018
Rails development mode memory leak and slowdown, also on new apps
View slow-rails-reload-development.md

This is a draft of an issue I intend to post on the rails/rails repo.

Update: the issue is posted

Hello,

TL;DR; My fairly large Rails app (173 models, 208 controllers) is suffering from a continuously increasing slowdown that makes it hard to work on it. Each reload of the code takes longer than the previous one, with delays increasing to minutes after just a few reloads. I have identified a cause and it's also present on new apps (rails new leaky). No solution yet.

For the past years I've been coping with an issue that Rails feels extremely slow when developing. I start the server, wait for it to boot up and open the site. It takes a minute or two before it loads.

View kea-connected.js
// features-logic.js
import PropTypes from 'prop-types'
import { kea } from 'kea'
export default kea({
actions: () => ({
toggleFeature: (feature) => ({ feature })
}),
reducers: ({ actions }) => ({
features: [{}, PropTypes.object, {
View kea-github.js
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { kea } from 'kea'
import { put, call } from 'redux-saga/effects'
import { delay } from 'redux-saga'
const API_URL = 'https://api.github.com'
@kea({
You can’t perform that action at this time.