Giter Club home page Giter Club logo

castra's Introduction

Hoplon Logo

Hoplon

clojars cljdoc badge

Hoplon is a ClojureScript library that unify some of the web platform's idiosyncrasies and present a fun way to design and build single-page web applications.

Hoplon tightly integrates with Javelin to reactively bind DOM elements to the underlying Javelin cell graph.

Quickstart

Install deps-new if you haven't already:

clojure -Ttools install-latest :lib io.github.seancorfield/deps-new :as new

And then generate a starter project with:

clojure -Sdeps '{:deps {io.github.hoplon/project-template {:git/tag "v1.0.0" :git/sha "14361f1"}}}' -Tnew create :template hoplon/hoplon :name your/app-name

Example

A small bit of Hoplon:

(ns view.index
  (:require
    [hoplon.core  :as h]
    [hoplon.dom]
    [javelin.core :as j]))

(defn my-list [& items]
  (h/div :class "my-list"
    (apply h/ul (map #(h/li (h/div :class "my-list-item" %)) items))))

(def clicks (j/cell 0))

(defn hello []
  (h/div
    (h/h1 "Hello, Hoplon")
    (my-list
      (h/span "first thing")
      (h/span "second thing"))
    (h/p (h/text "You've clicked ~{clicks} times, so far."))
    (h/button :click #(swap! clicks inc) "click me")))

Browser Support

Hoplon has been thoroughly tested on desktop and mobile devices against the following browsers:

IEdge Firefox Safari Chrome Opera Android

Documentation

Demos

Developing Hoplon itself

# build and install locally
clojure -T:build ci :snapshot true
clojure -T:build install :snapshot true

Testing

This setup will run tests using chrome-webdriver.

Setup

npm install
npm install -g karma-cli

Run

; Run tests in simple compilation
clojure -T:build test

; Run tests in advanced compilation
clojure -T:build advanced-test

Contributors

This project exists thanks to all the people who contribute.

License

Copyright (c) Alan Dipert and Micha Niskin. All rights reserved.

The use and distribution terms for this software are covered by the Eclipse
Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can
be found in the file epl-v10.html at the root of this distribution. By using
this software in any fashion, you are agreeing to be bound by the terms of
this license. You must not remove this notice, or any other, from this software.

castra's People

Contributors

alandipert avatar burn2delete avatar flyingmachine avatar jumblerg avatar laforge49 avatar micha avatar mynomoto avatar onetom avatar rwillig avatar waffle-iron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

castra's Issues

Castra endpoints don't work in IE 9+

I have observed that Castra endpoints appear not to work in IE versions 9 and up. I noticed this both in the TSP Demo app and in Castra Hello World example. More details to follow

Scaffolded project raises CORS error on localhost

Steps to reproduce

lein new hoplon-castra castra-cors-bug
cd castra-cors-bug
boot development
# In other terminal session:
curl http://localhost:8000

What happens

We get

No Origin Header Specified on Cross-Origin Request%

What should happen

We should get the same result which is returned when invoking curl -H 'Origin: http://localhost:8000' http://localhost:8000, i.e.

<!DOCTYPE html>
<html><head><meta charset="utf-8"><script type="text/javascript">window._hoplon_main_css = 'c6f4dce0-0384-11e4-9191-0800200c9a66.css';</script><script type="text/javascript" src="c6f4dce0-0384-11e4-9191-0800200c9a66.js"></script><script type="text/javascript">tailrecursion.hoplon.app_pages._index_DOT_html.hoploninit();</script></head><body></body></html>%

Batching notifications for multiple domains

How do we move server notifications to a web client?

  1. In the "good old days" the client would poll the server for anything the server wanted to send. Polling can be expensive, so the last thing we wanted was to have multiple polling loops--one was bad enough!
  2. Then we got the long poll. Basically the server would not respond to a poll request from the client until either a timeout occurred or the server had something to send. On receipt of a response, the client would then immediately poll again. So at any time the server had a pending request from a client that it could respond to when it had something to send.
  3. And then we got websockets. So a server could send anything to a client at any time.

Hoplon/castra is like the good old days all over again, except that there may be multiple polling loops as there may be multiple domains. Ouch! Lets develop an API for castra (or that can sit on top of websockets) that passes server notifications to a hoplon client's input cells. Later we can embellish the implementation of the API to support alternative transports.

First, we can register input cells as receiving a type of notification, where each type of notification is identified by a keyword. Of course, we might be able to get fancy and have the mapping handled without the need for registration.

Second, the notifications. These would be a map with an id and a type. The value of the id is a consecutively increasing number specific to each client; the id being used to determine which haplon input cell to update.

Third, we would also have an ack-number. When a server gets an ack-number, it will no longer send any notification with an id less than or equal to that ack-number. Poll requests sent to a server always contain an ack-number and are requests for all notifications with an id greater than the ack-number. On receipt of a poll request, the server drops all notifications that have been acknowledged and sends in a vector all the unacknowledged notifications.

Now when a server has a notification for a client, it assigns it the next notification id for that client and puts it in a sorted map with all the other pending notifications, keyed by that id, where each client has its own sorted map.

The API is pretty simple. A means of mapping notification types to cells on the client and a means of adding notifications to the pending notifications map for a client. We will also likely need a way to control the poll loop as well.

Refactor ring handler into middleware

Castra shouldn't return 404s. Instead it should pass through to the next handler. This would make it possible to chain multiple castra middleware, for example.

use worker threads to make ajax requests, introduce cljs futures, and eliminate jquery dependency

castra uses jquery for its (a) ajax fn and (b) promise. this dependency can be removed by (1) using the native XMLHttpRequest (2) making requests from a worker thread wrapped in a clojurescript future abstraction.

(defn xhr [{:keys [url credentials headers body]}]
  (doto (js/XMLHttpRequest.)
        (.open "POST" url false)
        (set-req-headers headers)
        (aset "withCredentials" credentials)
        (.send body)))

status is always nil on castra exceptions.

when ex-data is called on the the error at line 26, it returns only {:castra.core/exception true} from the first exception in :via instead of the :data we're really interested in.

https://github.com/hoplon/castra/blob/master/src/castra/middleware.clj#L26

#error {
 :cause "clj-http: status 401"
 :data {:status 401, :headers {"Access-Control-Expose-Headers" "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval", "Server" "GitHub.com", "Content-Type" "application/json; charset=utf-8", "Access-Control-Allow-Origin" "*", "X-Content-Type-Options" "nosniff", "Content-Length" "83", "X-Frame-Options" "deny", "Strict-Transport-Security" "max-age=31536000; includeSubdomains; preload", "X-RateLimit-Limit" "60", "X-RateLimit-Remaining" "54", "X-RateLimit-Reset" "1482225574", "Connection" "close", "Status" "401 Unauthorized", "X-GitHub-Request-Id" "CC09DC32:2ADB3:628F031:5858ED05", "X-GitHub-Media-Type" "github.v3; format=json", "Date" "Tue, 20 Dec 2016 08:34:13 GMT", "X-XSS-Protection" "1; mode=block", "Content-Security-Policy" "default-src 'none'"}, :body "{\"message\":\"Bad credentials\",\"documentation_url\":\"https://developer.github.com/v3\"}", :request-time 852, :trace-redirects ["https://api.github.com/user"], :orig-content-encoding nil}
 :via
 [{:type clojure.lang.ExceptionInfo
   :message "Server error."
   :data {:castra.core/exception true}
   :at [clojure.core$ex_info invokeStatic "core.clj" 4617]}
  {:type clojure.lang.ExceptionInfo
   :message "clj-http: status 401"
   :data {:status 401, :headers {"Access-Control-Expose-Headers" "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval", "Server" "GitHub.com", "Content-Type" "application/json; charset=utf-8", "Access-Control-Allow-Origin" "*", "X-Content-Type-Options" "nosniff", "Content-Length" "83", "X-Frame-Options" "deny", "Strict-Transport-Security" "max-age=31536000; includeSubdomains; preload", "X-RateLimit-Limit" "60", "X-RateLimit-Remaining" "54", "X-RateLimit-Reset" "1482225574", "Connection" "close", "Status" "401 Unauthorized", "X-GitHub-Request-Id" "CC09DC32:2ADB3:628F031:5858ED05", "X-GitHub-Media-Type" "github.v3; format=json", "Date" "Tue, 20 Dec 2016 08:34:13 GMT", "X-XSS-Protection" "1; mode=block", "Content-Security-Policy" "default-src 'none'"}, :body "{\"message\":\"Bad credentials\",\"documentation_url\":\"https://developer.github.com/v3\"}", :request-time 852, :trace-redirects ["https://api.github.com/user"], :orig-content-encoding nil}
   :at [slingshot.support$stack_trace invoke "support.clj" 201]}]
 :trace
 [[slingshot.support$stack_trace invoke "support.clj" 201]
  [clj_http.client$wrap_exceptions$fn__4098 invoke "client.clj" 196]
  [clj_http.client$wrap_accept$fn__4302 invoke "client.clj" 565]
  [clj_http.client$wrap_accept_encoding$fn__4308 invoke "client.clj" 579]
  [clj_http.client$wrap_content_type$fn__4297 invoke "client.clj" 555]
  [clj_http.client$wrap_form_params$fn__4389 invoke "client.clj" 726]
  [clj_http.client$wrap_nested_params$fn__4406 invoke "client.clj" 751]
  [clj_http.client$wrap_method$fn__4349 invoke "client.clj" 670]
  [clj_http.cookies$wrap_cookies$fn__1847 invoke "cookies.clj" 124]
  [clj_http.links$wrap_links$fn__3095 invoke "links.clj" 51]
  [clj_http.client$wrap_unknown_host$fn__4415 invoke "client.clj" 771]
  [clj_http.client$get invokeStatic "client.clj" 874]
  [clj_http.client$get doInvoke "client.clj" 870]
  [clojure.lang.RestFn invoke "RestFn.java" 423]
  [panoply.backend.github$get_user invokeStatic "github.clj" 19]
  [panoply.backend.github$get_user invoke "github.clj" 17]
  [panoply.backend.api$get_user invokeStatic "api.clj" 11]
  [panoply.backend.api$get_user invoke "api.clj" 9]
  [clojure.lang.Var invoke "Var.java" 375]
  [clojure.lang.AFn applyToHelper "AFn.java" 152]
  [clojure.lang.Var applyTo "Var.java" 700]
  [clojure.core$apply invokeStatic "core.clj" 646]
  [clojure.core$apply invoke "core.clj" 641]
  [castra.middleware$do_rpc invokeStatic "middleware.clj" 45]
  [castra.middleware$do_rpc invoke "middleware.clj" 41]
  [castra.middleware$wrap_castra$fn__1488$f__1489 invoke "middleware.clj" 127]
  [castra.middleware$wrap_castra$fn__1488$fn__1491 invoke "middleware.clj" 128]
  [castra.middleware$wrap_castra$fn__1488 invoke "middleware.clj" 128]
  [panoply.backend.github$wrap_token$fn__4526 invoke "github.clj" 29]
  [castra.middleware$wrap_castra_session$fn__1465 invoke "middleware.clj" 102]
  [clojure.lang.Var invoke "Var.java" 379]
  [ring.middleware.reload$wrap_reload$fn__7008 invoke "reload.clj" 38]
  [clojure.lang.Var invoke "Var.java" 379]
  [tailrecursion.clojure_adapter_servlet.impl$service invokeStatic "impl.clj" 137]
  [tailrecursion.clojure_adapter_servlet.impl$service invoke "impl.clj" 135]
  [clojure.lang.Var invoke "Var.java" 383]
  [tailrecursion.ClojureAdapterServlet service "ClojureAdapterServlet.java" 40]
  [org.eclipse.jetty.servlet.ServletHolder handle "ServletHolder.java" 816]
  [org.eclipse.jetty.servlet.ServletHandler doHandle "ServletHandler.java" 583]
  [org.eclipse.jetty.server.handler.ScopedHandler handle "ScopedHandler.java" 143]
  [org.eclipse.jetty.security.SecurityHandler handle "SecurityHandler.java" 548]
  [org.eclipse.jetty.server.session.SessionHandler doHandle "SessionHandler.java" 226]
  [org.eclipse.jetty.server.handler.ContextHandler doHandle "ContextHandler.java" 1113]
  [org.eclipse.jetty.servlet.ServletHandler doScope "ServletHandler.java" 511]
  [org.eclipse.jetty.server.session.SessionHandler doScope "SessionHandler.java" 185]
  [org.eclipse.jetty.server.handler.ContextHandler doScope "ContextHandler.java" 1047]
  [org.eclipse.jetty.server.handler.ScopedHandler handle "ScopedHandler.java" 141]
  [org.eclipse.jetty.server.handler.HandlerWrapper handle "HandlerWrapper.java" 119]
  [org.eclipse.jetty.server.Server handle "Server.java" 517]
  [org.eclipse.jetty.server.HttpChannel handle "HttpChannel.java" 302]
  [org.eclipse.jetty.server.HttpConnection onFillable "HttpConnection.java" 242]
  [org.eclipse.jetty.io.AbstractConnection$ReadCallback succeeded "AbstractConnection.java" 238]
  [org.eclipse.jetty.io.FillInterest fillable "FillInterest.java" 95]
  [org.eclipse.jetty.io.SelectChannelEndPoint$2 run "SelectChannelEndPoint.java" 57]
  [org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume produceAndRun "ExecuteProduceConsume.java" 213]
  [org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume run "ExecuteProduceConsume.java" 147]
  [org.eclipse.jetty.util.thread.QueuedThreadPool runJob "QueuedThreadPool.java" 654]
  [org.eclipse.jetty.util.thread.QueuedThreadPool$3 run "QueuedThreadPool.java" 572]
  [java.lang.Thread run "Thread.java" 745]]}

Exception at startup when clutch is used

Add [com.ashafa/clutch "0.4.0"]
to build.boot (using hoplon's template), and you'll have at startup:

2016-01-31 15:56:51.458:WARN:oejs.HttpChannel:qtp717638826-34: /
java.lang.RuntimeException: java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonFactory.createGenerator(Ljava/io/OutputStream;)Lcom/fasterxml/jackson/core/JsonGenerator;
at com.cognitect.transit.TransitFactory.writer(TransitFactory.java:72)
at cognitect.transit$writer.invoke(transit.clj:143)
at cognitect.transit$writer.invoke(transit.clj:137)
at castra.middleware$fn__5130.invoke(middleware.clj:56)
at castra.middleware$wrap_castra$fn__5168.invoke(middleware.clj:110)
at clojure.lang.Var.invoke(Var.java:379)
at ring.middleware.reload$wrap_reload$fn__977.invoke(reload.clj:22)
at ring.middleware.content_type$wrap_content_type$fn__448.invoke(content_type.clj:30)
at ring.middleware.not_modified$wrap_not_modified$fn__475.invoke(not_modified.clj:52)
at ring.adapter.jetty$proxy_handler$fn__1127.invoke(jetty.clj:24)
at ring.adapter.jetty.proxy$org.eclipse.jetty.server.handler.AbstractHandler$ff19274a.handle(Unknown Source)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:497)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.lang.Thread.run(Thread.java:745)
Caused by:
java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonFactory.createGenerator(Ljava/io/OutputStream;)Lcom/fasterxml/jackson/core/JsonGenerator;
at com.cognitect.transit.impl.WriterFactory.getJsonInstance(WriterFactory.java:111)
at com.cognitect.transit.TransitFactory.writer(TransitFactory.java:65)
at cognitect.transit$writer.invoke(transit.clj:143)
at cognitect.transit$writer.invoke(transit.clj:137)
at castra.middleware$fn__5130.invoke(middleware.clj:56)
at castra.middleware$wrap_castra$fn__5168.invoke(middleware.clj:110)
at clojure.lang.Var.invoke(Var.java:379)
at ring.middleware.reload$wrap_reload$fn__977.invoke(reload.clj:22)
at ring.middleware.content_type$wrap_content_type$fn__448.invoke(content_type.clj:30)
at ring.middleware.not_modified$wrap_not_modified$fn__475.invoke(not_modified.clj:52)
at ring.adapter.jetty$proxy_handler$fn__1127.invoke(jetty.clj:24)
at ring.adapter.jetty.proxy$org.eclipse.jetty.server.handler.AbstractHandler$ff19274a.handle(Unknown Source)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:497)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.lang.Thread.run(Thread.java:745)

Clojure client

Is it possible to use clojure for the client as well as the castra server, as opposed to clojurescript for the client?

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.