Git Product home page Git Product logo

cljs-spa's Introduction

This was just an weekend project when learning ClojureScript - not intended to be used other than for a couple of experiments

cljs-spa

A small client side framework for creating single page web applications in clojurescript based on features inspired by ideas in the excellent talk here: http://www.youtube.com/watch?v=V1Eu9vZaDYw and the book: http://www.manning.com/mikowski/

See the wiki for a guide on getting started - https://github.com/jasoncourcoux/cljs-spa/wiki/Getting-Started-Guide

Overview

The core of cljs-spa is a simple framework to help manage application state in a single clojure map, and a way for features to interact with the state and one another without having to be dependant upon each other. This allows a very pluggable model, allowing devlopment of standalone components which can be reused across multiple applications.

Features

A feature is a standalone component which can be plugged in to a cljs-spa web application. At a minimum they should contain a namespaced id, a set of behaviours and a function which knows how to initialise itself.

An example feature:-

(use 'cljs-spa.core)

(deffeature ::my-feature-id
            :behaviours [::render ::update]
            :init (fn [obj & data]
                    ;;We'll do something with the data here and return it
                    data))

Behaviours

Behaviours define what a feature can do and what functionality they perform - an example might be a "render" behaviour which allows a feature to create and insert itself at a particular point in the page structure. These should contain a namespaced id, a set of triggers and a reaction function.

(use 'cljs-spa.core)

(defbehaviour ::my-behaviour-id
              :triggers [:render :click]
              :reaction (fn [instance-id {:keys [key-one key-two]}]
                          ;; We should validate the data, and perform an action, the
                          ;; id is passed through as an indication of the specific instance
                          ;; of this feature, to allow multiple feature instances to co-exist
                          instance-id))                          

Instances

To actually use a feature an instance must be created, containing a unique namepsaced id (Note, for singletons, it is perfectly valid to use the same id for both a feature and an instance of it). Behaviours specific to this feature maybe added, and any custom state should be passed into the state map.

(use 'cljs-spa.core)

(create ::feature-id
        ::instance-id
        ::behaviours []
        ::state {})

License

Copyright © 2012-2013 Jason Courcoux

Distributed under the Eclipse Public License, the same as Clojure.

cljs-spa's People

Contributors

jasoncourcoux avatar

Watchers

 avatar James Cloos avatar Peter Courcoux 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.