blob: bc96aef6caceb2b150e11a75c00fa0e999df0250 (
plain) (
blame)
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
|
;;; Port of https://stackoverflow.com/questions/3984296/model-view-controller-design-pattern-code-example.
;;; View class.
(require 'eieio)
(eval-when-compile (require 'cl-lib))
(eval-when-compile (require 'cl-generic))
(require 'jsonrpc)
(defclass v-view ()
((button :accessor button)
(model :accessor model)
(controller :writer controller)
))
(cl-defmethod initialize-instance :after ((self v-view) &rest initargs)
(oset self button (make-instance (find-class 'button) 'm "Click Me"))
(oset self model (make-instance (find-class 'v-model-stub)))
(oset self controller (make-instance (find-class 'v-controller-stub) 'm (model self) 'b (button self))))
(defconst v--port-num 8194)
(defvar v--conn (make-instance 'jsonrpc-process-connection
:process (lambda ()
(open-network-stream
"*MVC JSON-RPC*" nil
"localhost" v--port-num))))
(defclass v-model-stub () (id :reader id))
(cl-defmethod initialize-instance :after ((self v-model-stub) &rest initargs)
(oset self id (jsonrpc-request v--conn :create-model)))
(cl-defgeneric get-number (model))
(cl-defmethod get-number ((model v-model-stub))
(jsonrpc-request v--conn :get-number '(:id (id model))))
(defclass v-controller-stub () (id :reader id))
(cl-defmethod initialize-instance :after ((self v-controller-stub) &rest initargs)
(oset self id (jsonrpc-request v--conn :create-controller)))
(cl-defgeneric on-button-clicked (controller))
(cl-defmethod on-button-clicked ((controller v-controller-stub))
(jsonrpc-request v--conn :on-button-clicked '(:id (id controller))))
|