-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathlink.lisp
87 lines (71 loc) · 3.1 KB
/
link.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
(in-package #:jupyter/widgets)
(defwidget link (widget)
((source
:initarg :source
:initform nil
:accessor widget-source
:trait :link)
(target
:initarg :target
:initform nil
:accessor widget-target
:trait :link))
(:default-initargs
:%model-name "LinkModel"
:%model-module +controls-module+
:%model-module-version +controls-module-version+
:%view-name ""
:%view-module +controls-module+
:%view-module-version +controls-module-version+)
(:documentation "Link Widget"))
(defwidget directional-link (link)
()
(:default-initargs
:%model-name "DirectionalLinkModel")
(:documentation "A directional link"))
(defmethod (setf trait) (new-value instance name)
(dolist (def (closer-mop:class-slots (class-of instance)))
(when (string= (symbol-name name) (symbol-name (closer-mop:slot-definition-name def)))
(setf (closer-mop:slot-value-using-class (class-of instance) instance def)
new-value))))
(defun trait (instance name)
(dolist (def (closer-mop:class-slots (class-of instance)))
(when (string= (symbol-name name) (symbol-name (closer-mop:slot-definition-name def)))
(return (closer-mop:slot-value-using-class (class-of instance) instance def)))))
(defgeneric link (source source-trait target target-trait &optional sync)
(:documentation "Create a link between traits in the client if possible")
(:method (source source-trait target target-trait &optional sync)
(when sync
(setf (trait target target-trait) (trait source source-trait)))
(observe
source source-trait
(lambda (instance type name old-value new-value src)
(declare (ignore instance type name old-value src))
(setf (trait target target-trait) new-value)))
(observe
target target-trait
(lambda (instance type name old-value new-value src)
(declare (ignore instance type name old-value src))
(setf (trait source source-trait) new-value))))
(:method ((source widget) source-trait (target widget) target-trait &optional sync)
(when sync
(setf (trait target target-trait) (trait source source-trait)))
(make-instance 'link
:source (list source source-trait)
:target (list target target-trait))))
(defgeneric directional-link (source source-trait target target-trait &optional sync)
(:documentation "Create a link between traits in the client if possible")
(:method (source source-trait target target-trait &optional sync)
(when sync
(setf (trait target target-trait) (trait source source-trait)))
(observe
source source-trait
(lambda (instance type name old-value new-value src)
(declare (ignore instance type name old-value src))
(setf (trait target target-trait) new-value))))
(:method ((source widget) source-trait (target widget) target-trait &optional sync)
(when sync
(setf (trait target target-trait) (trait source source-trait)))
(make-instance 'directional-link
:source (list source source-trait)
:target (list target target-trait))))