Giter VIP home page Giter VIP logo

elm-horizon's Introduction

elm-horizon

DISCLAIMER: This is a work in progress, not ready for production yet. Contribution and PR are welcome! ๐Ÿ™‚

Elm & Horizon Logo

Thin wrapper around Horizon JavaScript client API for writing Horizon application in Elm.

Collection API

Write Operation

insertCmd/replaceCmd/storeCmd/updateCmd/upsertCmd/removeAllCmd

*Cmd -> String -> List Json.Value -> Cmd msg

Insert / replace / store / update / upsert / remove one or more new documents into a Collection.

Parameters:
  • collectionName is the name of the Horizon collection
  • values is List of encoded Json.Value you want to insert / replace / store / update / upsert / remove to the collection.
Example:
insertCmd "chat_messages" [ chatMessageEncoder { id = 1, from = "elm", message = "Hello World!" } ]  
removeAllCmd "chat_messages" <| List.map Json.Encode.int [ 1, 2, 3 ]

removeCmd

removeCmd -> String -> Json.Value -> Cmd msg

Parameters:
  • collectionName is the name of the Horizon collection
  • value is the encoded Json.Value of the id/record of the data you want to delete.
Example:
removeCmd "chat_messages" <| Json.Encode.int 1

insertSub/replaceSub/storeSub/updateSub/upsertSub/removeAllSub/removeSub

*Sub -> (Result Error () -> msg) -> Sub msg

Subscription for the result of Insert / replace / store / update / upsert / remove operation.

Parameters:
  • tagger is the constructor for your msg that requires a Result
Example:
type Msg = InsertResponse (Result Error ())

subscriptions = insertSub InsertResponse 

Read Operations

fetchCmd/watchCmd

*Cmd -> String -> List Modifier -> Cmd msg

Parameters:
  • collectionName is the name of the Horizon collection
  • modifiers is the List of Modifier
Example:
watchCmd "chat_messages" [ Limit 10, Order "name" Ascending ]

fetchSub/watchSub

*Sub -> Decoder a -> (Result Error (List (Maybe a)) -> msg) -> Sub msg

Parameters:
  • decoder is the decoder for decoding the data
  • tagger is msg constructor for tagging the decoded data
Example:
type Msg = NewMessageMsg (Result Error (List (Maybe ChatMessage)))

subscriptions = watchSub NewMessageMsg

Modifiers

Above Json.Value

Restrict the range of results returned to values that sort above a given value.

Example:
Above <| encoder { price = 100.0 }

Below Json.Value

Restrict the range of results returned to values that sort below a given value.

Example:
Below <| encoder { value = 20 }

Find Json.Value

Retrieve a single document from a Collection.

Example:
Find <| encoder { id = 1 }

FindAll (List Json.Value)

Retrieve multiple documents from a Collection.

Example:
FindAll [ encoder { id = 1 }, encoder { id = 2 }]

Limit Int

Example:
Limit 10

Order String Direction

where Direction can be:

  • Ascending
  • Descending
Example:
Order "timestamp" Ascending

Examples:

To build and run the example, clone the repo, and then from the root folder of the repo, run this command:

$ npm install
$ npm start

and then open http://localhost:8000 from your browser to open the chat app, or http://localhost:8000/search.html to open the search app.

Make sure you have Horizon and RthinkDB installed on your machine. See http://horizon.io/install/ for installation instruction.

Authentication

TBA

Users & Groups

TBA

Permissions

TBA

elm-horizon's People

Contributors

abadi199 avatar

Watchers

Julian Dax 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.