diff options
author | Teddy Wing | 2021-02-03 19:12:40 +0100 |
---|---|---|
committer | Teddy Wing | 2021-02-03 19:21:32 +0100 |
commit | b5c2f3a6ed194245e9c584f25b28d8f7c8f90218 (patch) | |
tree | 90fec16922c592355281009a50aff85c18d45592 /l/src/config.lisp | |
parent | 857302a5ac0714087a1f8d068e3bc5a15a1393d8 (diff) | |
download | extreload-b5c2f3a6ed194245e9c584f25b28d8f7c8f90218.tar.bz2 |
config: Initialise a new websocket-driver client on new config
Add a new `make-config` function to construct a `config` object. This
creates a new websocket-driver client and stores it in the `ws-client`
slot in the `config`.
Before this, I thought about using a writer method on the `socket-url`
slot that creates a new client. This didn't work in `make-instance`
though. Perhaps there's a way to have the `:initarg` use the writer, but
I'm not sure.
Diffstat (limited to 'l/src/config.lisp')
-rw-r--r-- | l/src/config.lisp | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/l/src/config.lisp b/l/src/config.lisp index 6b31dac..eb8bede 100644 --- a/l/src/config.lisp +++ b/l/src/config.lisp @@ -13,10 +13,35 @@ :initarg :reload-current-tab :initform nil :reader reload-current-tab - :documentation "True if the current tab should be reloaded"))) + :documentation "True if the current tab should be reloaded") + + (ws-client + :documentation "WebSocket client"))) (defmethod print-object ((object config) stream) (print-unreadable-object (object stream :type t) - (with-slots (socket-url extension-ids reload-current-tab) object - (format stream ":socket-url ~s :extension-ids ~s :reload-current-tab ~s" - socket-url extension-ids reload-current-tab)))) + (with-slots (socket-url extension-ids reload-current-tab ws-client) object + (format stream + ":socket-url ~s :extension-ids ~s :reload-current-tab ~s :ws-client ~s" + socket-url extension-ids reload-current-tab ws-client)))) + +;; TODO: (make-config) instead, initialise ws-client in initialiser +(defgeneric (setf socket-url) (url config)) + +(defmethod (setf socket-url) (url (config config)) + "Set `socket-url` and initialise a new `websocket-driver:client` in the +`ws-client` slot" + (setf (slot-value config 'socket-url) url) + + (setf (slot-value config 'ws-client) (wsd:make-client url))) + +(defun make-config (&key socket-url extension-ids reload-current-tab) + (let ((config (make-instance 'config + :socket-url socket-url + :extension-ids extension-ids + :reload-current-tab reload-current-tab))) + + ;; Initialise a new websocket-driver client + (setf (slot-value config 'ws-client) (wsd:make-client socket-url)) + + config)) |