GithubHelp home page GithubHelp logo

Comments (2)

gadfly361 avatar gadfly361 commented on May 27, 2024

@phunanon Thanks for reporting, I will look in to this soon 👍

from re-pollsive.

gadfly361 avatar gadfly361 commented on May 27, 2024

@phunanon I am not able to reproduce. Can you provide the code that caused your error so we can try to debug?

When I tried with the latest re-frame, re-pollsive was working as expected. This is what I did:

  1. lein new re-frame mypoll
  2. add repollsive to project.clj :depencencies
(defproject mypoll "0.1.0-SNAPSHOT"                                                                                                                                     
  :dependencies [[org.clojure/clojure "1.10.1"]                                                                                                                         
                 [org.clojure/clojurescript "1.10.758"                                                                                                                  
                  :exclusions [com.google.javascript/closure-compiler-unshaded                                                                                          
                               org.clojure/google-closure-library                                                                                                       
                               org.clojure/google-closure-library-third-party]]                                                                                         
                 [thheller/shadow-cljs "2.8.110"]                                                                                                                       
                 [reagent "0.10.0"]                                                                                                                                     
                 [re-frame "0.12.0"]                                                                                                                                    
                 [re-pollsive "0.1.0"]]    
...
  1. Setup re-pollisve in project.clj
(ns mypoll.core                                                                                                                                                         
  (:require                                                                                                                                                             
   [reagent.core :as reagent]                                                                                                                                           
   [reagent.dom :as rdom]                                                                                                                                               
   [re-frame.core :as re-frame]                                                                                                                                         
   [mypoll.events :as events]                                                                                                                                           
   [mypoll.views :as views]                                                                                                                                             
   [mypoll.config :as config]                                                                                                                                           
   [mypoll.fx]                                                                                                                                                          
   ;; Add this (1 of 2)                                                                                                                                                 
   [re-pollsive.core :as poll]                                                                                                                                          
   ))                                                                                                                                                                   
                                                                                                                                                                        
                                                                                                                                                                        
(defn dev-setup []                                                                                                                                                      
  (when config/debug?                                                                                                                                                   
    (println "dev mode")))                                                                                                                                              
                                                                                                                                                                        
(defn ^:dev/after-load mount-root []                                                                                                                                    
  (re-frame/clear-subscription-cache!)                                                                                                                                  
  (let [root-el (.getElementById js/document "app")]                                                                                                                    
    (rdom/unmount-component-at-node root-el)                                                                                                                            
    (rdom/render [views/main-panel] root-el)))                                                                                                                          
                                                                                                                                                                        
(defn init []                                                                                                                                                           
  (re-frame/dispatch-sync [::events/initialize-db])                                                                                                                     
  ;; And this (2 of 2)                                                                                                                                                  
  (re-frame/dispatch-sync [::poll/init])                                                                                                                                
  (dev-setup)                                                                                                                                                           
  (mount-root))                                                                                                                                                         
  1. Add an event that will get called when the poller run
(ns mypoll.events                                                                                                                                                       
  (:require                                                                                                                                                             
   [re-frame.core :as re-frame]                                                                                                                                         
   [mypoll.db :as db]                                                                                                                                                   
   ))                                                                                                                                                                   
                                                                                                                                                                        
(re-frame/reg-event-db                                                                                                                                                  
 ::initialize-db                                                                                                                                                        
 (fn [_ _]                                                                                                                                                              
   db/default-db))                                                                                                                                                      
                                                                                                                                                                        
(re-frame/reg-event-fx                                                                                                                                                  
 ::log                                                                                                                                                                  
 (fn [coeffects [event & values]]                                                                                                                                       
   {:logger (apply str values)}))
  1. Register a logger effect in a new file called mypoll.fx
(ns mypoll.fx                                                                                                                                                           
  (:require [re-frame.core :as re-frame]))                                                                                                                              
                                                                                                                                                                        
                                                                                                                                                                        
(re-frame/reg-fx                                                                                                                                                        
 :logger                                                                                                                                                                
 (fn [value]                                                                                                                                                            
   (println value))) 
  1. Update mypoll.views to set the re-pollsive rules when the page is loaded
(ns mypoll.views                                                                                                                                                        
  (:require                                                                                                                                                             
   [re-frame.core :as re-frame]                                                                                                                                         
   [re-pollsive.core :as poll]                                                                                                                                          
   [mypoll.subs :as subs]                                                                                                                                               
   [mypoll.events :as events]                                                                                                                                           
   ))                                                                                                                                                                   
                                                                                                                                                                        
(defn main-panel []                                                                                                                                                     
  (let []                                                                                                                                                               
    (re-frame/dispatch                                                                                                                                                  
     [::poll/set-rules                                                                                                                                                  
      [{:interval                 4                                                                                                                                     
        :event                    [::events/log "POLL (every 4 seconds)"]                                                                                               
        :dispatch-event-on-start? true}                                                                                                                                 
       ]])                                                                                                                                                              
    (fn []                                                                                                                                                              
      (let [name (re-frame/subscribe [::subs/name])]                                                                                                                    
        [:div                                                                                                                                                           
         [:h1 "Hello from " @name]                                                                                                                                      
         ]))))     
  1. start the application by running lein dev, then navigate to localhost:8280 then open the console and observe the logs which should see a printout every four seconds.

from re-pollsive.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.