Skip to content

Commit

Permalink
Merge 21423b9 into 251aa72
Browse files Browse the repository at this point in the history
  • Loading branch information
svetlyak40wt committed Jun 2, 2022
2 parents 251aa72 + 21423b9 commit 1b77927
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/commands-hook.lisp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defpackage #:reblocks/commands-hook
(uiop:define-package #:reblocks/commands-hook
(:use #:cl)
(:import-from #:reblocks/hooks
#:on-application-hook-handle-http-request
Expand Down
10 changes: 6 additions & 4 deletions src/commands.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
(in-package #:reblocks/commands)


(defvar *commands* nil
"A list of commands to execute on a client as a result of action call.
(defvar *commands*)

These commands are collected during action processing and rendered to resulting JSON
as some sort of JSON-rpc calls to be esecuted on a client-side.")
(setf (documentation '*commands* 'variable)
"A list of commands to execute on a client as a result of action call.
These commands are collected during action processing and rendered to resulting JSON
as some sort of JSON-rpc calls to be esecuted on a client-side.")


(defun cl-symbol-to-js-symbol (symbol)
Expand Down
23 changes: 11 additions & 12 deletions src/dependencies.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -205,18 +205,17 @@ as a response to some action.")


(defmethod render-in-ajax-response ((dependency dependency))
(case (get-type dependency)
(:js
(let ((script (parenscript:ps* `(include_dom
,(get-url dependency)))))
(log:debug "Rendering js dependency in ajax response" dependency)
(send-script script :before-load)))

(:css
(let ((script (parenscript:ps* `(include_css
,(get-url dependency)))))
(log:debug "Rendering css dependency in ajax response" dependency)
(send-script script :before-load)))))
(let ((url (get-url dependency)))
(case (get-type dependency)
(:js
(let ((script (parenscript:ps* `(include_dom ,url))))
(log:debug "Rendering js dependency in ajax response" dependency)
(send-script script :before-load)))

(:css
(let ((script (parenscript:ps* `(include_css ,url))))
(log:debug "Rendering css dependency in ajax response" dependency)
(send-script script :before-load))))))


(defmethod render-in-head ((dependency remote-dependency))
Expand Down
10 changes: 10 additions & 0 deletions src/doc/changelog.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@
"CSS"
"HTTP")
:external-links (("Ultralisp" . "https://ultralisp.org")))

(0.45.1 2022-06-02
"""
Fixed
=====
* Fixed the way how dependencies are rendered in AJAX action response. Previously,
when many widgets of the same class were updated on one user action Reblocks sent
a duplicate css/js dependencies.
""")
(0.45.0 2022-02-14
"""
Changed
Expand Down
21 changes: 14 additions & 7 deletions src/request-handler.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,20 @@ customize behavior."))
(defmethod handle-ajax-request ((app app))
(log:debug "Handling AJAX request")

(write
(to-json
(list :|commands| (get-collected-commands)))
;; Seems like a hack, because we have to know implementation details of reblocks/html here.
;; TODO: hide implementation details.
:stream *stream*
:escape nil))
;; Generate code to embed new dependencies into the page on the fly.
;; This render will generate commands to include necessary pieces
;; of JS and CSS into the page.
(mapc #'reblocks/dependencies:render-in-ajax-response
reblocks/dependencies::*page-dependencies*)

(let ((commands (get-collected-commands)))
(write
(to-json
(list :|commands| commands))
;; Seems like a hack, because we have to know implementation details of reblocks/html here.
;; TODO: hide implementation details.
:stream *stream*
:escape nil)))


(defmethod handle-normal-request ((app app))
Expand Down
5 changes: 3 additions & 2 deletions src/request.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@
(in-package #:reblocks/request)


(defvar *request* nil
"Holds current request from a browser.")
(defvar *request*)
(setf (documentation '*request* 'variable)
"Holds current request from a browser.")


(defun get-uri (&key (request *request*))
Expand Down
11 changes: 10 additions & 1 deletion src/server.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,16 @@ This function serves all started applications and their static files."
(prepare-hooks
(reblocks/hooks:with-handle-http-request-hook (env)

(let* ((path-info (getf env :path-info))
(let* ((path-info (getf env
;; Previously, we used :path-info
;; attribute here, but it has %20 replaced
;; with white-spaces and get-route breaks
;; on URIs having spaces, because it calls
;; cl-routes and it calls puri:parse-uri
;; which requires URI to be url-encoded.
;; Hope, this change will not break other
;; places where PATH-INFO is used.
:request-uri))
(hostname (getf env :server-name))
(route (get-route path-info))
(app (search-app-for-request-handling path-info hostname)))
Expand Down
7 changes: 1 addition & 6 deletions src/widgets/render-methods.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@

(let ((widget-dependencies (get-dependencies widget)))
;; Update new-style dependencies
(push-dependencies widget-dependencies)

(when (ajax-request-p)
;; Generate code to embed new dependencies into the page on the fly
(mapc #'render-in-ajax-response
widget-dependencies)))
(push-dependencies widget-dependencies))

(with-html
(:tag
Expand Down

0 comments on commit 1b77927

Please sign in to comment.