Skip to content

Instantly share code, notes, and snippets.

@awwx
awwx / mobserve.cljc
Last active May 4, 2024 11:51
observe Missionary task and flow events
;; SPDX-License-Identifier: EPL-2.0 OR MIT
(ns mobserve
(:require
[missionary.core :as m])
(:import
missionary.Cancelled))
;; Encapsulate differences between Clojure and ClojureScript
;; on how IFn and IDeref are implemented.
@awwx
awwx / transmute.md
Last active May 1, 2024 08:25
transmute

Here's a mechanism for transforming a discrete input flow into an output flow where the internal process state can be implemented with loop/recur. As an example I provide an implementation of "batching with both a maximum size and a maximum delay" referenced in leonoel/missionary#109.

Transforming discrete flows

A common pattern for discrete flows is that we want to create an output flow from an input flow, where:

@awwx
awwx / mobserve.cljc
Last active May 4, 2024 11:19
observe Missionary task and flow events
;; Newer version at https://gist.github.com/awwx/6d02e6ea702bdc499bcf847e9b9bb98f
(ns mobserve
(:require
[missionary.core :as m]))
;; Encapsulate differences between Clojure and ClojureScript
;; on how IFn and IDeref are implemented.
#?(:clj
@awwx
awwx / lifecycle.cljc
Last active March 28, 2024 01:57
lifecycle on-mount/on-unmount that works with reactive values
(ns lifecycle
(:require
[missionary.core :as m]
[hyperfiddle.electric :as e]
[hyperfiddle.electric-dom2 :as dom]))
;; Electric doesn't guarantee, in general, that reactive updates
;; will be performed in a particular order... but this specific
;; recipe is believed to be OK due to details of Electric's
;; execution model.
@awwx
awwx / event_listener.cljc
Created March 27, 2024 03:48
A version of Electric's dom/on! which only needs to attach the event listener on mount and remove on unmount
; The goal here is to provide a coupling between Electric
; and JavaScript event listeners that's more idiomatic on the
; JavaScript side: namely, that the event listener can be
; attached only once on mount and only needs to be removed on
; unmount.
;
; The strategy is to use e/fn to convert the reactive event
; listener fn into a continuous flow of event listener functions,
; which we can then sample to get the latest listener function
; when an event occurs.
@awwx
awwx / main.cljc
Last active March 28, 2024 10:25
Electric without atoms
(ns main
(:require
[missionary.core :as m]
[hyperfiddle.electric :as e]
[hyperfiddle.electric-dom2 :as dom])
#?(:cljs
(:require-macros [main])))
;; event emitter with only one subscriber

Keybase proof

I hereby claim:

  • I am awwx on github.
  • I am awwx (https://keybase.io/awwx) on keybase.
  • I have a public key ASBcCNrU3yTY8JqL1Fi4ZzYCQ8_DekuL3JsljX3zRa_R_Ao

To claim this, I am signing this object:

@awwx
awwx / crash_configuration.txt
Created December 28, 2019 15:49
TLA+ Workbench crash configuration
*** Date: Saturday, December 28, 2019 at 10:48:27 AM Eastern Standard Time
*** Platform Details:
*** System properties:
applicationXMI=org.eclipse.ui.workbench/LegacyIDE.e4xmi
awt.toolkit=sun.lwawt.macosx.LWCToolkit
ds.delayed.keepInstances=true
eclipse.application=org.lamport.tla.toolbox.application
eclipse.buildId=1.6.0
@awwx
awwx / tla-workbench-crash.txt
Created December 28, 2019 15:41
TLA Workbench 1.6.0 crash running File/Produce PDF Version
Process: toolbox [23470]
Path: /Applications/TLA+ Toolbox.app/Contents/MacOS/toolbox
Identifier: org.lamport.tla.toolbox.product.product
Version: 1.6.0 (1.6.0.201907102009)
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: toolbox [23470]
User ID: 501
Date/Time: 2019-12-28 10:20:21.253 -0500
Verifying that +andrewwilcox is my openname (Bitcoin username). https://onename.io/andrewwilcox