All Projects → kibu-australia → Pushy

kibu-australia / Pushy

Licence: epl-1.0
Clojurescript library for quick and easy HTML5 pushState

Programming Languages

clojure
4091 projects
clojurescript
191 projects

Labels

Projects that are alternatives of or similar to Pushy

Riptide
Client-side response routing for Spring
Stars: ✭ 169 (-20.28%)
Mutual labels:  routing
Fault tolerant router
A daemon, running in background on a Linux router or firewall, monitoring the state of multiple internet uplinks/providers and changing the routing accordingly. LAN/DMZ internet traffic is load balanced between the uplinks.
Stars: ✭ 182 (-14.15%)
Mutual labels:  routing
Osrm Frontend
Modular rewrite of the OSRM frontend using LRM
Stars: ✭ 197 (-7.08%)
Mutual labels:  routing
Vite Plugin Voie
File system based routing plugin for Vite
Stars: ✭ 172 (-18.87%)
Mutual labels:  routing
Routemagic
Utility Library to get the most out of ASP.NET Routing.
Stars: ✭ 180 (-15.09%)
Mutual labels:  routing
Ataraxy
A data-driven Ring routing and destructuring library
Stars: ✭ 187 (-11.79%)
Mutual labels:  routing
Libosmscout
Libosmscout is a C++ library for offline map rendering, routing and location lookup based on OpenStreetMap data
Stars: ✭ 159 (-25%)
Mutual labels:  routing
Ui Router
The de-facto solution to flexible routing with nested views in AngularJS
Stars: ✭ 13,738 (+6380.19%)
Mutual labels:  routing
Arouteserver
A tool to automatically build (and test) feature-rich configurations for BGP route servers.
Stars: ✭ 181 (-14.62%)
Mutual labels:  routing
Atlasr
Atlasr is a truly open-source and free map browser.
Stars: ✭ 196 (-7.55%)
Mutual labels:  routing
Dcompass
[WIP] High-performance programmable DNS server aiming at robustness, speed, and flexibility
Stars: ✭ 174 (-17.92%)
Mutual labels:  routing
Navi
🧭 Declarative, asynchronous routing for React.
Stars: ✭ 2,069 (+875.94%)
Mutual labels:  routing
Elefant
Elefant, the refreshingly simple PHP CMS and web framework.
Stars: ✭ 188 (-11.32%)
Mutual labels:  routing
Flow builder
Flutter Flows made easy! A Flutter package which simplifies flows with a flexible, declarative API.
Stars: ✭ 169 (-20.28%)
Mutual labels:  routing
Next Routes
Universal dynamic routes for Next.js
Stars: ✭ 2,354 (+1010.38%)
Mutual labels:  routing
Rayo.js
Micro framework for Node.js
Stars: ✭ 170 (-19.81%)
Mutual labels:  routing
Openrouteservice App
🚙 The open source route planner app with plenty of features.
Stars: ✭ 187 (-11.79%)
Mutual labels:  routing
Aqueduct
Dart HTTP server framework for building REST APIs. Includes PostgreSQL ORM and OAuth2 provider.
Stars: ✭ 2,412 (+1037.74%)
Mutual labels:  routing
Lime Packages
OpenWrt packages composing LibreMesh meta-firmware for wireless mesh networking
Stars: ✭ 204 (-3.77%)
Mutual labels:  routing
Peering Manager
Peering sessions management tool
Stars: ✭ 189 (-10.85%)
Mutual labels:  routing

pushy

Build Status

A Clojurescript library for quick and easy HTML5 pushState.

Install

Clojars Project

Usage

Setup

You can construct a new instance by calling the pushy function.

pushy takes in two arguments:

  • dispatch fn: gets called when there is a match
  • match fn: checks if the path matches any routes defined.

Optionally, you can specify an :identity-fn which parses and returns the route based on the result of the match fn.

Event listeners

You can start the event listeners with the start! method.

This adds an event listener to all click events, which dispatches on all matched routes. Bypasses on Alt, Shift, Meta, Ctrl keys and middle clicks.

The stop! method will tear down all event listeners of the pushy instance.

Routing libraries

pushy should work with any routing library:

Secretary

(ns foo.core
  (:require [secretary.core :as secretary :include-macros true :refer-macros [defroute]]
            [pushy.core :as pushy]))

(secretary/set-config! :prefix "/")

(defroute index "/foo" []
  (.log js/console "Hi"))

(def history (pushy/pushy secretary/dispatch!
                          (fn [x] (when (secretary/locate-route x) x))))

;; Start event listeners
(pushy/start! history)

Bidi

(ns foo.core
  (:require [bidi.bidi :as bidi]
            [pushy.core :as pushy]))

(def state (atom {}))

(def app-routes
  ["/" {"foo" :foo}])

(defn set-page! [match]
  (swap! state assoc :page match))

(def history
  (pushy/pushy set-page! (partial bidi/match-route app-routes)))

(pushy/start! history)

Silk

(ns foo.core
  (:require [domkm.silk :as silk]
            [pushy.core :as pushy]))

(def state (atom {}))

(def app-routes
  (silk/routes [[:foo [["/foo"]]]]))

(defn set-page! [match]
  (swap! state assoc :page match))

(def history
  (pushy/pushy set-page! (partial silk/arrive app-routes)))

(pushy/start! history)

Router

(ns foo.core
  (:require [pushy.core :as pushy]
            [darkleaf.router :as r]))

(r/defcontroller root-controller
  (show [_req]
    :root))

(r/defcontroller pages-controller
  (index [_req]
    :pages-index))

(def routing
  (r/group
    (r/resource :root root-controller, :segment false)
    (r/resources :pages :page pages-controller)))

(def handler (r/make-handler routing))

(def history (pushy/pushy (fn [response] (prn response))
                          (fn [uri] (handler {:uri uri, :request-method :get}))))

(pushy/start! history)

#_(pushy/set-token! history "/")
#_(pushy/set-token! history "/pages")

Sibiro

(ns foo.core
  (:require [sibiro.core :as sibiro]
            [pushy.core :as pushy]))

(def state (atom {}))

(defn set-page! [match]
  (assoc state :page match))

(def routes
  {[:get "/home" :home]})

(defn match-uri [uri]
  (:route-handler (sibiro/match-uri (sibiro/compile-routes routes) uri :get)))

(def history (pushy/pushy set-page! match-uri))

(pushy/start! history)

URL handling

By default pushy will dispatch on all relative URLs and absolute URLs that match the window's origin. This means that all external links will be bypassed.

It is possible to specify which URLs are processable to pushy by specifying a custom predicate function :processable-url? in the constructor. This function is passed a single argument which is an instance of goog.URI.

goog.history.HTML5History methods

You can set the history state manually by calling the set-token! method. This will call the dispatch fn on a successfully matched path.

Example:

(set-token! history "/foo")

(get-token history)
;; => /foo

Likewise, you can call replace-token! which will also call the dispatch fn and replace the current history state without affecting the rest of the history stack.

License

Copyright © 2017

Distributed under the Eclipse Public License either version 1.0

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].