Skip to content

Instantly share code, notes, and snippets.

Hog, the language

This document describes the features of Hog.

General syntax

Comments

// Hog comments start with //
// 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 }
// 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'
@mariusandra
mariusandra / kea-devtools-alpha.js
Last active December 4, 2019 20:39
Kea DevTools (ALPHA)
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 April 27, 2023 11:35
dimensions plugin for kea
import { setPluginContext, getPluginContext, useMountedLogic } from 'kea'
import { useEffect } from 'react'
/*
usage:
kea({
dimensions: {
// key: [defaultValue, calcFunction],
isSmallScreen: [false, window => window.innerWidth < 640],
// 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
@mariusandra
mariusandra / routeset.txt
Created May 14, 2018 08:27
routeset debug
… 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 11:20
Rails development mode memory leak and slowdown, also on new apps

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.

// features-logic.js
import PropTypes from 'prop-types'
import { kea } from 'kea'
export default kea({
actions: () => ({
toggleFeature: (feature) => ({ feature })
}),
reducers: ({ actions }) => ({
features: [{}, PropTypes.object, {