Skip to content

Instantly share code, notes, and snippets.

@bensu
bensu / no-instrument.clj
Last active August 29, 2015 14:15
Optional Instrumentation for Om components
(ns no-instrument.core
(:require[om.core :as om :include-macros true]
[om.dom :as dom :include-macros true]))
(enable-console-print!)
;; Instrumentation
;; ===============
(defn paint-component
@bensu
bensu / local-state.clj
Created February 27, 2015 10:56
Shows communication of local state between two components using core.async
(ns ^:figwheel-always local-state.core
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [om.core :as om :include-macros true]
[om.dom :as dom :include-macros true]
[cljs.core.async :refer [put! chan <!]]))
(enable-console-print!)
(defonce app-state (atom {}))
(ns react-components.core
(:require [reagent.core :as reagent :refer [atom]]))
(enable-console-print!)
(defonce app-state
(atom {:text "Hello world!"
:plain {:comment "and I can take props from the atom"}}))
(defn comment-box []
@bensu
bensu / routing-trouble.cljs
Created March 27, 2015 11:53
Routing trouble
(ns notes.core
(:import goog.History
goog.history.EventType)
(:require [reagent.core :as reagent :refer [atom]]
[secretary.core :as secretary]
[reagent.session :as session]
[reagent-forms.core :refer [bind-fields]]
[ajax.core :refer [POST]]
[goog.events])
(:require-macros [secretary.core :refer [defroute]]))
@bensu
bensu / nashorn-test-output
Created April 19, 2015 20:25
ClojureScript Nashorn tests
carlos@clojurescript: ./script/test-none
Analyzing file:/home/carlos/OpenSource/clojurescript/src/cljs/cljs/core.cljs
Compiling test/cljs/baz.cljs
WARNING: baz is a single segment namespace at line 1 test/cljs/baz.cljs
Compiling test/cljs/cljs/ns_test/bar.cljs
Compiling test/cljs/cljs/binding_test_other_ns.cljs
Compiling test/cljs/cljs/binding_test.cljs
Analyzing file:/home/carlos/OpenSource/clojurescript/src/cljs/cljs/test.cljs
Analyzing file:/home/carlos/OpenSource/clojurescript/src/cljs/clojure/string.cljs
Compiling test/cljs/cljs/keyword_other.cljs
@bensu
bensu / nashorn-minimal.clj
Last active August 29, 2015 14:19
Nashortn minimal failing case
(ns cljs.core-test
(:refer-clojure :exclude [iter])
(:require [cljs.test :refer-macros [deftest testing is]]))
(deftest test-atoms-and-volatile
(let [v (volatile! 1)]
(testing "Testing volatile"
(is (volatile? v))
(is (not (volatile? (atom 1))))
(is (= 2 (vreset! v 2)))
@bensu
bensu / failure
Last active August 29, 2015 14:19
Nashorn smaller fail case
The minimal error (below) disappears when test-919-generic-cas is deleted. It seems to be that the Protocol clashing comes when MyCustomAtom is used, not only defined. The error also disappears if `state` inside MyCustomAtom is changed to snail. Note that Volatile in cljs.core is also defined in terms of a state attribute.
Note that even though `compare-and-set!` calls `-deref` it raises no exceptions.
ERROR in (test-919-generic-cas) (Error:NaN:NaN)
testing CLJS-919, CAS should on custom atom types
expected: (== (clojure.core/deref a0) 20)
actual:
#<Error: No protocol method IDeref.-deref defined for type cljs.core-test/MyCustomAtom: [object Object]>
@bensu
bensu / condensed.js
Created April 21, 2015 18:30
Minimal PASSING case
var goog = goog || {};
goog.typeOf = function(value) {
var s = typeof value;
if (s == "object") {
if (value) {
if (value instanceof Array) {
return "array";
} else {
if (value instanceof Object) {
@bensu
bensu / README
Last active August 29, 2015 14:19
Minimal failing case for core.cljs
This Gist shows a potential bug in nashorn 1.8.0_40/1.8.0_45. It works properly in Java 9. It was logged with Review ID: JI-9020683.
After compiling a reduced version of core.cljs (the ClojureScript language) and a minimal test,
V8 and Spidermonkey print 1 and 10 when the compiled script runs. Nashorn prints 1 and then throws
the custom exception "Error: No protocol method IDeref defined for type :[object Object]"
The file compiled.js is a distilled version of the real compiled file that has the minimum code to
fail. Any of the lines marked with // X solve the problem when deleted for 1.8.0_40. Deleting the
commented function solves the problem both for 1.8.0_40 and 1.8.0_45. Said function is not referenced
in the code at all.
@bensu
bensu / stack
Created May 11, 2015 14:01
stack trace for rewriteAliasProp in advanced compilation
java.lang.IllegalStateException
at com.google.common.base.Preconditions.checkState(Preconditions.java:158)
at com.google.javascript.jscomp.CollapseProperties.rewriteAliasProps(CollapseProperties.java:266)
at com.google.javascript.jscomp.CollapseProperties.inlineGlobalAliasIfPossible(CollapseProperties.java:239)
at com.google.javascript.jscomp.CollapseProperties.inlineAliases(CollapseProperties.java:181)
at com.google.javascript.jscomp.CollapseProperties.process(CollapseProperties.java:116)
at com.google.javascript.jscomp.PhaseOptimizer$NamedPass.process(PhaseOptimizer.java:285)
at com.google.javascript.jscomp.PhaseOptimizer.process(PhaseOptimizer.java:217)
at com.google.javascript.jscomp.Compiler.optimize(Compiler.java:1972)
at com.google.javascript.jscomp.Compiler.compileInternal(Compiler.java:765)