Giter Site home page Giter Site logo

weasel's Introduction

weasel

WebSocket-connected REPL environment for ClojureScript.

Clojars Project

COMPATIBILITY NOTICE

For ClojureScript versions 0.0-2311 or 0.0-2371, you will need Weasel version 0.4.1. Otherwise, use 0.3.0. (0.4.0 was a broken release the author managed to botch).

why?

The traditional browser-connected REPL shipped with ClojureScript and Chas Emerick's refactored browser REPL Austin are both great ways to evaluate ClojureScript inside a running browser from a REPL. But since their communications go over an <iframe> transport via Closure's goog.net.xpc library, they can only be used in contexts that allow iframes and on pages which are served over the same protocol as the iframe (http://). This means you can't use these REPLs to connect to a page served off the filesystem (file://), in a Chrome extension (chrome-extension://), or as part of a Spotify Application (sp://). Weasel provides a REPL connection to these and similar environments.

usage

Weasel is intended to be used with Chas Emerick's piggieback nREPL middleware. Once you've set that up, add weasel as a dependency (available from Clojars) to your Leiningen project.clj:

[weasel "0.4.1"]

Start up lein repl and piggieback the Weasel REPL environment onto the nREPL session, optionally specifying a port (defaults to 9001) and an address to bind to (defaults to "127.0.0.1").

user> (require 'weasel.repl.websocket)
nil
user> (cemerick.piggieback/cljs-repl
        :repl-env (weasel.repl.websocket/repl-env
                   :ip "0.0.0.0" :port 9001))

<< started Weasel server on ws://0.0.0.0:9001 >>
Type `:cljs/quit` to stop the ClojureScript REPL
nil

In your project's ClojureScript, require the Weasel client namespace and connect to the REPL.

(ns my.cljs.core
  (:require [weasel.repl :as ws-repl]))

(ws-repl/connect "ws://localhost:9001")

You may optionally specify the following:

:verbose ; boolean, defaults to true
:print ; :repl to print only to the repl,
       ; :console to print only to the console
       ; #{:repl :console} to print to both
       ; or any variadic function to handle printing differently.
       ; defaults to :repl
:on-open, :on-error, :on-close ; fns for handling websocket lifecycle events.
                               ; default for all is nil

Connecting with options:

(ws-repl/connect "ws://localhost:9001"
   :verbose true
   :print #{:repl :console}
   :on-error #(print "Error! " %))

Load the page in your WebSocket-enabled environment (probably a browser) and start evaluating ClojureScript at the REPL:

cljs.user> (= (js/Number. 34) (js/Number. 34))
false
cljs.user> (do (js/alert "Hello world!") 42)
42

Note that unless a client is connected to the WebSocket channel, evaluation will fail:

cljs.user> (+ 5 10)
java.io.IOException: No client connected to Websocket
nil

Moreover, only a single browser can be connected to the REPL at once. Attempts to connect from another browser will fail with an error message in the browser's console. This may be addressed in future versions.

example

An example project is included in the weasel-example subdirectory of this project.

need help?

If you have any feedback or issues to report, feel free to open an issue on GitHub. Otherwise, ping dsrx on freenode and I'll do my best to help you.

weasel's People

Contributors

tomjakubowski avatar tomconnors avatar noklesta avatar bbatsov avatar jenanwise avatar jmreidy avatar the-kenny avatar r0man avatar

Watchers

Emile Snyder avatar James Cloos avatar  avatar

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.