Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
/paniPublic

Idiomatic Clojure/ClojureScript library for Firebase

License

NotificationsYou must be signed in to change notification settings

verma/pani

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deprecation Warning: A fork of this project is under active development here:https://github.com/crisptrutski/matchbox .The future of pani itself is undecided at this time.

A convenience library to access Firebase from Clojurescript.

Build Status

The goal of this library is not to provide access to the entire functionality offered by Firebase, but to make it convenient to use Firebase as a data store from within Clojurescript.

Current version

The library is in its infancy. The current version is0.0.3.

Clojars Project

Features

Pani offers several benefits over raw JS interop:

  • Idiomatic constructs
  • Async channels or callbacks for change notifications
  • Javascript objects abstraction

This library, for now, is entirely based on how I intend to use this library (may be with Om etc.) and would grow as I discover more things I'd like it to do. Pull requests welcome!

Usage

Requirepani:

(:require [pani.cljs.core :as p])       ; for clojurescript(:require [pani.clojure.core :as p])    ; for clojure

Create a root object:

(def r (p/root "https://your-app.firebaseio.com/"))

Bind a callback to recieve callback notifications when avalue notification occurs:

(p/bind r :value :age #(log %1))

Thebind call accepts either a key or a seq of keys (get-in style):

(p/bind r :value [:info :world] #(log %1))

You can also bind to other Firebase notification events, e.g. thechild_added notification:

(p/bind r :child_added :messages #(log %1))

If no callback is specified, thebind call returns an async channel:

(let [c (p/bind r :child_added :messages)]  (go-loop [msg (<! c)]    (.log js/console "New message (go-loop):" (:message msg))    (recur (<! c))))

Use theset! call to set a value, likebind this function accepts either a single key or a seq of keys:

(p/set! r [:info :world] "welcome")(p/set! r :age 100)

Use thepush! function to push values into a collection:

(p/push! r :messages {:message "hello"})

Finally, use thewalk-root function to get a new child node:

(def messages-root (p/walk-root r :messages))(p/bind messages-root :child_added [] #(log %1))

Clojurescript Examples

Note that, most examples will require you to add your Firebase app url to the example. You'd most likely have to edit a line like the following in one of the source files (most likelycore.cljs):

;; TODO: Set this to a firebase app URL(def firebase-app-url "https://your-app.firebaseio.com/")

All examples are available under theexamples directory. To run a Clojurescript example just run the respectivelein command to build it:

lein cljsbuild once <example-name>

This should build and place amain.js file along with anout directory in the example's directory. You should now be able to go to the example's directory and open theindex.html file in a web-browser.

License

Copyright © 2014 Uday Verma

Distributed under the Eclipse Public License either version 1.0 or (atyour option) any later version.

About

Idiomatic Clojure/ClojureScript library for Firebase

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp