Skip to content

Instantly share code, notes, and snippets.

View mike-thompson-day8's full-sized avatar

Mike Thompson mike-thompson-day8

  • Sydney, Australia
View GitHub Profile

You create a fsm via an effect:

(reg-event-fx
  :id
  (fn [_ _])
    {:fsm  {:create {:id   123
                     :initial-state {}
                     :log-fn  (fn [fsm-db db trigger new-state] ...)

Recently Rich Hickey's communicated to the Clojure community via a Gist. When reading it, I was struck by how similar it was to his previous communication via Reddit.

And that lead me to wonder: if that previous communication didn't do the job, why would this latest one work when it is so similar? Will his new communication cause some useful structural change or will we just see an action replay of this same community processes in another 6 months?

Unfortunately, I think we are stuck in a cycle and we'll soon see a repeat of this angst. Do the same thing, you get the same result. Fine, but what is it that might cause Rich Hickey's interventions to be ineffective? What could be done differently?

Before going on, we should acknowledge that there is a cost to these interventions. Rich Hickey appears angry when he writes them and he is striking out and down, and this

@mike-thompson-day8
mike-thompson-day8 / dnd.cljs
Last active February 7, 2018 00:43
DnD example for re-com
;; What you are looking at: I just picked up this code from one of our apps, and dumped it here unedited.
;; It shows how to do DnD with reagent/re-com, using the terrible HTML5 API.
;; I haven't done anything to shrink this code down. It is a straight cut and paste from live code
;; so it is complicated by many real world, application issues, sorry. It is also very early
;; code for us, on coming to cljs, so it probably contains all sorts of ugly and embarasing attrocities.
;; But it does work.
;; So, as background, when trying to understand what the code is doing, imagine a panel containing
;; a "table" of rows. Each row displays "a single daypart" item (it doesn't matter what a daypart is)
View functions with a subscription are not pure. They are obtaining an "input" from a non argument source.
From a practical point view, I haven't been motivated to solve this problem - non-local reasoning is not a problem, and neither is testing because subscribe is easy to stub out, so it feels like you are dealing with a pure function - HOWEVER from a theoretical point of view, this is certainly a "pebble in the shoe". In due course, I'd like it fixed.
Here's a quick sketch of approximated how (not all issues resolved):
1. create a new `reg-view` function thru which all views are associated with an `id`. Make this registration much like `reg-sub` in the way that you can nominate N signal inputs via a signals function.
2. change Reagent so that the first element of vector can be an `id` previously registered by `reg-view`. So, instead of `:div`, you could use `:something/panelX`
Would be used like this (notice how similar this is to reg-sub):

In re-com v0.10.0, we made changes to the way popover-anchor-wrapper interacts with its :popover child.

These changes are backwards imcompatable and, as a result, you'll probably have to made some light modifications to the components given as the :popover.

Very Simple Change

Typically, popover-context-wrapper is used to create the :popover child of popover-anchor-wrapper, like this:

[popover-anchor-wrapper 
    ... 

I've only written this from a cljs point of view.
code is untested

Callback version:

(defn wait-for-event
  "Waits for an event to occur and then calls 'callback-fn'.
  'ids' can be a single event id, or a collection of ids.
  'callback-fn' is called when any one of the nominated event ids occurs.
@mike-thompson-day8
mike-thompson-day8 / Booting.md
Last active July 17, 2016 12:23
An Draft Document on Async Tasks In re-frame
@mike-thompson-day8
mike-thompson-day8 / todomvc.subs-v3.cljs
Last active July 1, 2016 06:20
todomvc.subs-v3.cljs
;; Version 3
;; What follows is indicative of how re-frame's new `regsub` might work/look.
;;
;; I've taken the todomvc subscriptions and rewritten them using a new, mythical
;; macro `regsub`, just to see if I like the result.
;; Original: https://github.com/Day8/re-frame/blob/4b931fe67208c10ae960c683fd837b03c38f88b0/examples/todomvc/src/todomvc/subs.cljs
(ns todomvc.subs
(:require [re-frame.core :refer [regsub]]))
> This Gist is out of date. It has been superseded by
> https://gist.github.com/mike-thompson-day8/d61692451166e206a9c43771c8b389fc
;; Version 2
;; WARNING: this code is untested. It probably doesn't even compile.
;; It is meant to be indicative of how `regsub` might work/look.
;; I've taken the todomvc subscriptions and I've rewritten them using a new mythical
;; macro `regsub`.
;; Existing: https://github.com/Day8/re-frame/blob/4b931fe67208c10ae960c683fd837b03c38f88b0/examples/todomvc/src/todomvc/subs.cljs
> This Gist is out of date. It has been superseded by
> https://gist.github.com/mike-thompson-day8/d61692451166e206a9c43771c8b389fc
;; WARNING: this code is untested. In fact not even compiled.
;; It is just meant to be indicative of how `regsub` might work/look.
(ns todomvc.subs
(:require-macros [reagent.ratom :refer [reaction]])
(:require [re-frame.core :refer [register-sub]]))