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
<html lang="en">
<head>
<title>Unit Tests</title>
<!-- Use a monspace font and a dark theme -->
<!-- Colour Palet from http://clrs.cc/ -->
<style>
body {
font-family: Courier, "Courier New", monospace;
font-size: 11;

de-dupe Build Status

The Problem

Persistent Data Strctures use structural sharing to create an efficient in-memory representation, but these same structures can be a problem to serialize/deserialize.

First, the shared parts are duplicated in the serialised output which can lead to a large and inefficient representation.

Second, when the process is reversed, deserialization doesn't recreate the original, shared, effcient in-memory representation because sharing information was lost in the original serialisation.

@mike-thompson-day8
mike-thompson-day8 / debug.md
Last active May 23, 2016 16:58
An alternative to the offical re-frame debug middleware
(defn debug-cljs-devtools
  "This is a drop-in alternative for the offical re-frame `debug` middleware
  It is better because: 
    - it writes data, rather than strings, to js/console. This better leverages  
      the power of cljs-devtols.
    - it exploits js/console's ability to colorize text, hopefully making the 
      output easier to grok."
  [handler]
 (fn debug-handler
@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]]))
@mike-thompson-day8
mike-thompson-day8 / Booting.md
Last active July 17, 2016 12:23
An Draft Document on Async Tasks In re-frame
> 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]]))

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.

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 
    ... 
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):