text-change optimisations (#971)

This commit is contained in:
alwx 2017-04-21 10:37:44 +03:00 committed by Roman Volosovskyi
parent 96dc348d7c
commit 735639776b
12 changed files with 50 additions and 46 deletions

View File

@ -47,9 +47,8 @@
(assoc db :layout-height height))) (assoc db :layout-height height)))
(register-handler :set-chat-ui-props (register-handler :set-chat-ui-props
(fn [{:keys [current-chat-id] :as db} [_ ui-element value chat-id]] (fn [{:keys [current-chat-id] :as db} [_ kvs]]
(let [chat-id (or chat-id current-chat-id)] (update-in db [:chat-ui-props current-chat-id] merge kvs)))
(assoc-in db [:chat-ui-props chat-id ui-element] value))))
(register-handler :toggle-chat-ui-props (register-handler :toggle-chat-ui-props
(fn [{:keys [current-chat-id chat-ui-props] :as db} [_ ui-element chat-id]] (fn [{:keys [current-chat-id chat-ui-props] :as db} [_ ui-element chat-id]]
@ -59,9 +58,9 @@
(register-handler :show-message-details (register-handler :show-message-details
(u/side-effect! (u/side-effect!
(fn [_ [_ details]] (fn [_ [_ details]]
(dispatch [:set-chat-ui-props :show-bottom-info? true]) (dispatch [:set-chat-ui-props {:show-bottom-info? true
(dispatch [:set-chat-ui-props :show-emoji? false]) :show-emoji? false
(dispatch [:set-chat-ui-props :bottom-info details])))) :bottom-info details}]))))
(register-handler :load-more-messages (register-handler :load-more-messages
(fn [{:keys [current-chat-id loading-allowed] :as db} _] (fn [{:keys [current-chat-id loading-allowed] :as db} _]

View File

@ -45,9 +45,9 @@
(when-not sequential-params (when-not sequential-params
(input-model/join-command-args prefill)))]) (input-model/join-command-args prefill)))])
(dispatch [:set-chat-input-metadata metadata]) (dispatch [:set-chat-input-metadata metadata])
(dispatch [:set-chat-ui-props :show-suggestions? false]) (dispatch [:set-chat-ui-props {:show-suggestions? false
(dispatch [:set-chat-ui-props :result-box nil]) :result-box nil
(dispatch [:set-chat-ui-props :validation-messages nil]) :validation-messages nil}])
(dispatch [:load-chat-parameter-box command 0]) (dispatch [:load-chat-parameter-box command 0])
(if sequential-params (if sequential-params
(js/setTimeout (js/setTimeout
@ -145,7 +145,7 @@
:address current-account-id}] :address current-account-id}]
(dispatch [:set-chat-input-text nil chat-id]) (dispatch [:set-chat-input-text nil chat-id])
(dispatch [:set-chat-input-metadata nil chat-id]) (dispatch [:set-chat-input-metadata nil chat-id])
(dispatch [:set-chat-ui-props :sending-in-progress? false]) (dispatch [:set-chat-ui-props {:sending-in-progress? false}])
(cond (cond
command-message command-message
(dispatch [:check-commands-handlers! data]) (dispatch [:check-commands-handlers! data])
@ -173,15 +173,15 @@
::proceed-validation-messages ::proceed-validation-messages
(handlers/side-effect! (handlers/side-effect!
(fn [db [_ command chat-id {:keys [markup validationHandler parameters] :as errors} proceed-fn]] (fn [db [_ command chat-id {:keys [markup validationHandler parameters] :as errors} proceed-fn]]
(let [set-errors #(do (dispatch [:set-chat-ui-props :validation-messages %]) (let [set-errors #(do (dispatch [:set-chat-ui-props {:validation-messages %
(dispatch [:set-chat-ui-props :sending-in-progress? false]))] :sending-in-progress? false}]))]
(cond (cond
markup markup
(set-errors markup) (set-errors markup)
validationHandler validationHandler
(do (dispatch [::execute-validation-handler validationHandler parameters set-errors proceed-fn]) (do (dispatch [::execute-validation-handler validationHandler parameters set-errors proceed-fn])
(dispatch [:set-chat-ui-props :sending-in-progress? false])) (dispatch [:set-chat-ui-props {:sending-in-progress? false}]))
:default :default
(proceed-fn)))))) (proceed-fn))))))
@ -201,8 +201,8 @@
(do (do
(when fullscreen (when fullscreen
(dispatch [:choose-predefined-expandable-height :result-box :max])) (dispatch [:choose-predefined-expandable-height :result-box :max]))
(dispatch [:set-chat-ui-props :result-box on-send]) (dispatch [:set-chat-ui-props {:result-box on-send
(dispatch [:set-chat-ui-props :sending-in-progress? false]) :sending-in-progress? false}])
(react-comp/dismiss-keyboard!)) (react-comp/dismiss-keyboard!))
(dispatch [::request-command-data (dispatch [::request-command-data
{:command command {:command command
@ -241,7 +241,7 @@
:send-current-message :send-current-message
(handlers/side-effect! (handlers/side-effect!
(fn [{:keys [current-chat-id] :as db} [_ chat-id]] (fn [{:keys [current-chat-id] :as db} [_ chat-id]]
(dispatch [:set-chat-ui-props :sending-in-progress? true]) (dispatch [:set-chat-ui-props {:sending-in-progress? true}])
(let [chat-id (or chat-id current-chat-id) (let [chat-id (or chat-id current-chat-id)
chat-command (input-model/selected-chat-command db chat-id) chat-command (input-model/selected-chat-command db chat-id)
seq-command? (get-in chat-command [:command :sequential-params]) seq-command? (get-in chat-command [:command :sequential-params])
@ -255,7 +255,7 @@
(dispatch [:proceed-command chat-command chat-id]) (dispatch [:proceed-command chat-command chat-id])
(dispatch [:clear-seq-arguments chat-id])) (dispatch [:clear-seq-arguments chat-id]))
(let [text (get-in db [:chats chat-id :input-text])] (let [text (get-in db [:chats chat-id :input-text])]
(dispatch [:set-chat-ui-props :sending-in-progress? false]) (dispatch [:set-chat-ui-props {:sending-in-progress? false}])
(when-not (input-model/text-ends-with-space? text) (when-not (input-model/text-ends-with-space? text)
(dispatch [:set-chat-input-text (str text const/spacing-char)])))) (dispatch [:set-chat-input-text (str text const/spacing-char)]))))
(dispatch [::send-message nil chat-id])))))) (dispatch [::send-message nil chat-id]))))))

View File

@ -62,7 +62,7 @@
:else :else
(dispatch [:prepare-command! chat-id params'])))) (dispatch [:prepare-command! chat-id params']))))
(dispatch [:set-chat-ui-props :sending-in-progress? false])))) (dispatch [:set-chat-ui-props {:sending-in-progress? false}]))))
(register-handler :prepare-command! (register-handler :prepare-command!
(u/side-effect! (u/side-effect!
@ -78,7 +78,7 @@
(cu/check-author-direction db chat-id))] (cu/check-author-direction db chat-id))]
(log/debug "Handler data: " request handler-data (dissoc params :commands :command-message)) (log/debug "Handler data: " request handler-data (dissoc params :commands :command-message))
(dispatch [:update-message-overhead! chat-id network-status]) (dispatch [:update-message-overhead! chat-id network-status])
(dispatch [:set-chat-ui-props :sending-in-progress? false]) (dispatch [:set-chat-ui-props {:sending-in-progress? false}])
(dispatch [::send-command! add-to-chat-id (assoc params :command command') hidden-params]) (dispatch [::send-command! add-to-chat-id (assoc params :command command') hidden-params])
(when (cu/console? chat-id) (when (cu/console? chat-id)
(dispatch [:console-respond-command params])) (dispatch [:console-respond-command params]))

View File

@ -90,11 +90,11 @@
(fn [] (fn []
(if @show-actions (if @show-actions
[touchable-highlight [touchable-highlight
{:on-press #(dispatch [:set-chat-ui-props :show-actions? false])} {:on-press #(dispatch [:set-chat-ui-props {:show-actions? false}])}
[view st/action [view st/action
[icon :up st/up-icon]]] [icon :up st/up-icon]]]
[touchable-highlight [touchable-highlight
{:on-press #(dispatch [:set-chat-ui-props :show-actions? true])} {:on-press #(dispatch [:set-chat-ui-props {:show-actions? true}])}
[view st/action [view st/action
[chat-icon]]])))) [chat-icon]]]))))
@ -184,7 +184,7 @@
layout-height [:get :layout-height] layout-height [:get :layout-height]
input-text [:chat :input-text]] input-text [:chat :input-text]]
{:component-did-mount #(dispatch [:check-autorun]) {:component-did-mount #(dispatch [:check-autorun])
:component-will-unmount #(dispatch [:set-chat-ui-props :show-emoji? false])} :component-will-unmount #(dispatch [:set-chat-ui-props {:show-emoji? false}])}
[view {:style st/chat-view [view {:style st/chat-view
:on-layout (fn [event] :on-layout (fn [event]
(let [height (.. event -nativeEvent -layout -height)] (let [height (.. event -nativeEvent -layout -height)]

View File

@ -95,7 +95,7 @@
subtitle] subtitle]
icon-name :icon}] icon-name :icon}]
[touchable-highlight {:on-press (fn [] [touchable-highlight {:on-press (fn []
(dispatch [:set-chat-ui-props :show-actions? false]) (dispatch [:set-chat-ui-props {:show-actions? false}])
(when handler (when handler
(handler)))} (handler)))}
[view st/action-icon-row [view st/action-icon-row
@ -132,5 +132,5 @@
^{:key action} [action-view action]))]])))) ^{:key action} [action-view action]))]]))))
(defn actions-view [] (defn actions-view []
[overlay {:on-click-outside #(dispatch [:set-chat-ui-props :show-actions? false])} [overlay {:on-click-outside #(dispatch [:set-chat-ui-props {:show-actions? false}])}
[actions-list-view]]) [actions-list-view]])

View File

@ -78,7 +78,7 @@
:status message-status}])) :status message-status}]))
(into {})) (into {}))
statuses (vals (merge participants user-statuses))] statuses (vals (merge participants user-statuses))]
[overlay {:on-click-outside #(dispatch [:set-chat-ui-props :show-bottom-info? false])} [overlay {:on-click-outside #(dispatch [:set-chat-ui-props {:show-bottom-info? false}])}
[container (* st/item-height (count statuses)) [container (* st/item-height (count statuses))
[list-view {:dataSource (lw/to-datasource statuses) [list-view {:dataSource (lw/to-datasource statuses)
:enableEmptySections true :enableEmptySections true

View File

@ -41,7 +41,7 @@
[view style/commands-root [view style/commands-root
[view style/command-list-icon-container [view style/command-list-icon-container
[touchable-highlight {:on-press #(do (dispatch [:toggle-chat-ui-props :show-suggestions?]) [touchable-highlight {:on-press #(do (dispatch [:toggle-chat-ui-props :show-suggestions?])
(dispatch [:set-chat-ui-props :validation-messages nil]) (dispatch [:set-chat-ui-props {:validation-messages nil}])
(dispatch [:update-suggestions]))} (dispatch [:update-suggestions]))}
[view style/commands-list-icon [view style/commands-list-icon
(if show-suggestions? (if show-suggestions?
@ -65,12 +65,13 @@
input-focused? (subscribe [:chat-ui-props :input-focused?])] input-focused? (subscribe [:chat-ui-props :input-focused?])]
(fn [{:keys [set-layout-height height]}] (fn [{:keys [set-layout-height height]}]
[text-input [text-input
{:ref #(dispatch [:set-chat-ui-props :input-ref %]) {:ref #(when %
(dispatch [:set-chat-ui-props {:input-ref %}]))
:accessibility-label id/chat-message-input :accessibility-label id/chat-message-input
:multiline true :multiline true
:default-value (or @input-text "") :default-value (or @input-text "")
:editable (not @sending-in-progress?) :editable (not @sending-in-progress?)
:on-blur #(do (dispatch [:set-chat-ui-props :input-focused? false]) :on-blur #(do (dispatch [:set-chat-ui-props {:input-focused? false}])
(set-layout-height 0)) (set-layout-height 0))
:on-content-size-change (when-not @input-focused? :on-content-size-change (when-not @input-focused?
#(let [h (-> (.-nativeEvent %) #(let [h (-> (.-nativeEvent %)
@ -82,18 +83,21 @@
(.-height))] (.-height))]
(set-layout-height h)) (set-layout-height h))
:on-change-text #(do (dispatch [:set-chat-input-text %]) :on-change-text #(do (dispatch [:set-chat-input-text %])
(dispatch [:load-chat-parameter-box (:command @command)]) (if @command
(when (not @command) (do
(dispatch [:set-chat-input-metadata nil]) (dispatch [:load-chat-parameter-box (:command @command)])
(dispatch [:set-chat-ui-props :result-box nil])) (dispatch [:set-chat-ui-props {:validation-messages nil}]))
(dispatch [:set-chat-ui-props :validation-messages nil])) (do
(dispatch [:set-chat-input-metadata nil])
(dispatch [:set-chat-ui-props {:result-box nil
:validation-messages nil}]))))
:on-selection-change #(let [s (-> (.-nativeEvent %) :on-selection-change #(let [s (-> (.-nativeEvent %)
(.-selection))] (.-selection))]
(when (and (= (.-end s) (+ 2 (count (get-in @command [:command :name])))) (when (and (= (.-end s) (+ 2 (count (get-in @command [:command :name]))))
(get-in @command [:command :sequential-params])) (get-in @command [:command :sequential-params]))
(dispatch [:chat-input-focus :seq-input-ref]))) (dispatch [:chat-input-focus :seq-input-ref])))
:on-focus #(do (dispatch [:set-chat-ui-props :input-focused? true]) :on-focus #(dispatch [:set-chat-ui-props {:input-focused? true
(dispatch [:set-chat-ui-props :show-emoji? false])) :show-emoji? false}])
:style (style/input-view height) :style (style/input-view height)
:placeholder-text-color style/color-input-helper-placeholder :placeholder-text-color style/color-input-helper-placeholder
:auto-capitalize :sentences}]))) :auto-capitalize :sentences}])))
@ -141,11 +145,11 @@
(fn [{:keys [command-width]}] (fn [{:keys [command-width]}]
(when (get-in @command [:command :sequential-params]) (when (get-in @command [:command :sequential-params])
(let [{:keys [placeholder hidden type]} (get-in @command [:command :params @arg-pos])] (let [{:keys [placeholder hidden type]} (get-in @command [:command :params @arg-pos])]
[text-input (merge {:ref #(dispatch [:set-chat-ui-props :seq-input-ref %]) [text-input (merge {:ref #(dispatch [:set-chat-ui-props {:seq-input-ref %}])
:style (style/seq-input-text command-width) :style (style/seq-input-text command-width)
:default-value (or @seq-arg-input-text "") :default-value (or @seq-arg-input-text "")
:on-change-text #(do (dispatch [:set-chat-seq-arg-input-text %]) :on-change-text #(do (dispatch [:set-chat-seq-arg-input-text %])
(dispatch [:set-chat-ui-props :validation-messages nil])) (dispatch [:set-chat-ui-props {:validation-messages nil}]))
:secure-text-entry hidden :secure-text-entry hidden
:placeholder placeholder :placeholder placeholder
:blur-on-submit false :blur-on-submit false
@ -184,8 +188,8 @@
[touchable-highlight [touchable-highlight
{:on-press #(do (dispatch [:set-chat-input-text nil]) {:on-press #(do (dispatch [:set-chat-input-text nil])
(dispatch [:set-chat-input-metadata nil]) (dispatch [:set-chat-input-metadata nil])
(dispatch [:set-chat-ui-props :result-box nil]) (dispatch [:set-chat-ui-props {:result-box nil
(dispatch [:set-chat-ui-props :validation-messages nil]) :validation-messages nil}])
(dispatch [:clear-seq-arguments]))} (dispatch [:clear-seq-arguments]))}
[view style/input-clear-container [view style/input-clear-container
[icon :close_gray style/input-clear-icon]]])]))}))) [icon :close_gray style/input-clear-icon]]])]))})))
@ -252,7 +256,8 @@
:on-layout #(let [h (-> (.-nativeEvent %) :on-layout #(let [h (-> (.-nativeEvent %)
(.-layout) (.-layout)
(.-height))] (.-height))]
(dispatch [:set-chat-ui-props :input-height h]))} (when (> h 0)
(dispatch [:set-chat-ui-props {:input-height h}])))}
[animated-view {:style (style/container container-anim-margin bottom-anim-margin)} [animated-view {:style (style/container container-anim-margin bottom-anim-margin)}
(when (str/blank? @input-text) (when (str/blank? @input-text)
[commands-view]) [commands-view])

View File

@ -20,7 +20,7 @@
:number-of-lines 1 :number-of-lines 1
:font :medium} :font :medium}
title] title]
[touchable-highlight {:on-press #(dispatch [:set-chat-ui-props :result-box nil])} [touchable-highlight {:on-press #(dispatch [:set-chat-ui-props {:result-box nil}])}
[view style/header-close-container [view style/header-close-container
[icon :close_light_gray style/header-close-icon]]]]]) [icon :close_light_gray style/header-close-icon]]]]])

View File

@ -16,7 +16,7 @@
(when-not loading (when-not loading
(dispatch [:set-command-argument [0 url]])) (dispatch [:set-command-argument [0 url]]))
(when (and dynamicTitle (not (str/blank? title))) (when (and dynamicTitle (not (str/blank? title)))
(dispatch [:set-chat-ui-props :result-box (assoc result-box :title title)]))))) (dispatch [:set-chat-ui-props {:result-box (assoc result-box :title title)}])))))
(defn web-view-error [] (defn web-view-error []
(r/as-element (r/as-element

View File

@ -21,7 +21,7 @@
(cond (cond
handler-error handler-error
(when-let [markup (:markup handler-error)] (when-let [markup (:markup handler-error)]
(dispatch [:set-chat-ui-props :validation-messages (cu/generate-hiccup markup)])) (dispatch [:set-chat-ui-props {:validation-messages (cu/generate-hiccup markup)}]))
result result
(let [command' (assoc command-message :handler-data returned) (let [command' (assoc command-message :handler-data returned)

View File

@ -77,7 +77,7 @@
[web3 {:keys [message-id to] :as pending-message}] [web3 {:keys [message-id to] :as pending-message}]
{:pre [(valid? :delivery/pending-message pending-message)]} {:pre [(valid? :delivery/pending-message pending-message)]}
(debug :add-prepeared-pending-message!) (debug :add-prepeared-pending-message!)
(let [message (select-keys pending-message [:from :to :topics :payload]) (let [message (select-keys pending-message [:from :to :topics :payload])
pending-message' (assoc pending-message :message message pending-message' (assoc pending-message :message message
:id message-id)] :id message-id)]
(swap! messages assoc-in [web3 message-id to] pending-message') (swap! messages assoc-in [web3 message-id to] pending-message')

View File

@ -205,10 +205,10 @@
(dispatch [::remove-pending-message message_id])) (dispatch [::remove-pending-message message_id]))
(dispatch [:clear-selected-transaction]) (dispatch [:clear-selected-transaction])
(dispatch [::remove-transaction id]) (dispatch [::remove-transaction id])
(dispatch [:set-chat-ui-props :validation-messages error_message])) (dispatch [:set-chat-ui-props {:validation-messages error_message}]))
:else :else
(dispatch [:set-chat-ui-props :validation-messages nil]))))) (dispatch [:set-chat-ui-props {:validation-messages nil}])))))
(register-handler :clear-selected-transaction (register-handler :clear-selected-transaction
(fn [db _] (fn [db _]