Fork me on GitHub
#reagent
<
2019-02-16
>
tomaas16:02:10

hi, using the firebase lib from cljsjs (aset (js/firebase.auth) "languageCode" "fr") expression does work when compiled with :advanced option.

tomaas16:02:30

firebase.auth.Auth.prototype.languageCode; appears, which i suppose the firebase wrapper in cljsjs uses

manandearth18:02:08

Hi @gadfly361, In re-pressed What will be the pattern for dispatching a key-press event that's mapping updates when the db updates ? My re-frame app is an interactive representation of the solar system. the visible elements (which are maps) as well as the attributes (keys and values) are selected interactively. The result is interpolated to sound and I manage to do this fine dispatching an on-change or on-hover event [:audio value1 value2]. I'd like to be able to dispatch this event with keys in the home row, so I made this vector key-vec [65 83 68 70 71 72 74 75 76 186 192 222 ] (key-code for home row) and I'm trying to map these on a set-keydown-rules with a for loop...

(defn keyboard []                                                                                                                               
  (let [selected-attr @(subscribe [::subs/selected-attr])                       ;the key whose values will be extracted from all selected maps                                                                
        spheres @(subscribe [::subs/sorted-spheres])                             ;the filtered list of maps                                                              
        adshr @(subscribe [::subs/envelope])                                           ;user defined first value for audio event                                                         
        key-vec [65 83 68 70 71 72 74 75 76 186 192 222 90]]          ;the keyboard's home row to be mapped                                                                          
    (for [body spheres :when (:vis body)]                                                                                                       
      (dispatch                                                                                                                                 
       [::rp/set-keydown-rules                                                                                                                  
        {:event-keys                                                                                                                            
         [[:audio adshr (interpolate (selected-attr body))]                        ;interpolate is a function that will output the second required value for the audio event                                                             
          [{:keyCode                                                                                                                            
            (nth key-vec (.indexOf spheres body))                                                                                               
            }]]}]))))
Naive... I know ... What will work?

gadfly36118:02:14

@adamgefen You will need to map the event-keys into a vector and then dispatch set-keydown-rules. set-keydown-rules is a replacement of the current rules instead of being addidtive

gadfly36118:02:48

So your current for loop would only result with keydown rules for the last thing in the for loop

manandearth19:02:03

I'll give it a go. Thanks!

👍 5
manandearth20:02:12

perfect! I made the function:

(defn key-event-vec []                                                                                                                          
  (let [selected-attr @(subscribe [::subs/selected-attr])                                                                                       
        spheres @(subscribe [::subs/sorted-spheres])                                                                                            
        adshr @(subscribe [::subs/envelope])                                                                                                    
        key-vec [65 83 68 70 71 72 74 75 76 186 192 222 90]]                                                                                    
    {:event-keys (into [] (for [body spheres :when (:vis body)]                                                                                 
                            [[:audio adshr (interpolate (selected-attr body))]                                                                  
                             [{:keyCode (nth key-vec (.indexOf spheres body))}]]))}))                                                           
                  
followed by:
(defn keyboard []                                                                                                                               
  (dispatch                                                                                                                                     
   [::rp/set-keydown-rules (key-event-vec)]))
brilliant! thanks.

gadfly36120:02:10

Awesome! Np :)