Skip to content

Instantly share code, notes, and snippets.

@mfikes
Last active August 29, 2015 14:19
Show Gist options
  • Save mfikes/0a6ea54290da88803afd to your computer and use it in GitHub Desktop.
Save mfikes/0a6ea54290da88803afd to your computer and use it in GitHub Desktop.
Nashorn volatiles "like" atoms
$ git diff
diff --git a/src/cljs/cljs/core.cljs b/src/cljs/cljs/core.cljs
index 2794acc..8f15796 100644
--- a/src/cljs/cljs/core.cljs
+++ b/src/cljs/cljs/core.cljs
@@ -3882,7 +3882,7 @@ reduces them without incurring seq initialization"
[iref]
(.-validator iref))
-(deftype Volatile [^:mutable state]
+(deftype Volatile [^:mutable state padding]
IVolatile
(-vreset! [_ new-state]
(set! state new-state))
@@ -3893,7 +3893,7 @@ reduces them without incurring seq initialization"
(defn volatile!
"Creates and returns a Volatile with an initial value of val."
[val]
- (Volatile. val))
+ (Volatile. val nil))
(defn volatile?
"Returns true if x is a volatile."
This causes an expectedly small diff in the :advanced JS output:
< function Pi(c,d,g){return r.c(c.qb(null),d)?(Mi(c,g),!0):!1}function Qi(c){this.state=c;this.m=32768;this.v=0}Qi.prototype.xd=function(c,d){return this.state=d};Qi.prototype.qb=function(){return this.state};function Ci(c){return new Qi(c)}function Ri(c){return c instanceof Qi}
---
> function Pi(c,d,g){return r.c(c.qb(null),d)?(Mi(c,g),!0):!1}function Qi(c,d){this.state=c;this.padding=d;this.m=32768;this.v=0}Qi.prototype.xd=function(c,d){return this.state=d};Qi.prototype.qb=function(){return this.state};function Ci(c){return new Qi(c,null)}function Ri(c){return c instanceof Qi}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment