Skip to content
Browse files

Split the mixins out into their own file.

  • Loading branch information...
1 parent 81f5883 commit b9c5c1b947b95a92a18b646a0e421ca60874b3dd @skeeto committed Apr 9, 2013
Showing with 52 additions and 33 deletions.
  1. +52 −0 @-mixins.el
  2. +0 −33 @.el
View
52 @-mixins.el
@@ -0,0 +1,52 @@
+;;; @-mixins.el --- useful mixin prototypes for @
+
+;; This is free and unencumbered software released into the public domain.
+
+;;; Commentary:
+
+;; The mixins provided:
+
+;; * @soft-get
+;; * @immutable
+;; * @watchable
+
+;; See each variable's documentation for more info.
+
+;;; Code:
+
+(require '@)
+
+(defvar @soft-get (@extend :default-get nil)
+ "Mixin: don't throw errors on unbound properties.")
+
+(def@ @soft-get :get (_property)
+ "If no DEFAULT is provided for PROPERTY, return @:default-get."
+ @:default-get)
+
+(defvar @immutable (@extend :immutable-error t)
+ "Don't allow changes on this object. Causes error if :immutable-error is t.")
+
+(def@ @immutable :set (property _value)
+ "Don't allow setting of properties on this object."
+ (when @:immutable-error
+ (error "Object is immutable, cannot set %s" property)))
+
+(defvar @watchable (@extend :watchers nil)
+ "Allow subscribing to changes to this object.")
+
+(def@ @watchable :watch (callback)
+ "Subscribe to this object's changes."
+ (push callback @:watchers))
+
+(def@ @watchable :unwatch (callback)
+ "Subscribe to this object's changes."
+ (setf @:watchers (remove callback @:watchers)))
+
+(def@ @watchable :set (property new)
+ (dolist (callback @:watchers)
+ (funcall callback @@ property new))
+ (@^:set property new))
+
+(provide '@-mixins)
+
+;;; @-mixins.el ends here
View
33 @.el
@@ -166,39 +166,6 @@ If :default, don't produce an error but return the provided value."
"Return a list of the keys directly on @@."
(loop for (key value) on (aref @@ 1) by #'cddr collect key))
-;; Other useful prototypes
-
-(defvar @soft-get (@extend :default-get nil)
- "Mixin: don't throw errors on unbound properties.")
-
-(def@ @soft-get :get (_property)
- "If no DEFAULT is provided for PROPERTY, return @:default-get."
- @:default-get)
-
-(defvar @immutable (@extend :immutable-error t)
- "Don't allow changes on this object. Causes error if :immutable-error is t.")
-
-(def@ @immutable :set (property _value)
- "Don't allow setting of properties on this object."
- (when @:immutable-error
- (error "Object is immutable, cannot set %s" property)))
-
-(defvar @watchable (@extend :watchers nil)
- "Allow subscribing to changes to this object.")
-
-(def@ @watchable :watch (callback)
- "Subscribe to this object's changes."
- (push callback @:watchers))
-
-(def@ @watchable :unwatch (callback)
- "Subscribe to this object's changes."
- (setf @:watchers (remove callback @:watchers)))
-
-(def@ @watchable :set (property new)
- (dolist (callback @:watchers)
- (funcall callback @@ property new))
- (@^:set property new))
-
;; Top-level Object Management
(defun @--list-all ()

0 comments on commit b9c5c1b

Please sign in to comment.
Something went wrong with that request. Please try again.