Giter Site home page Giter Site 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 rohanorton 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

Watchers

 avatar  avatar  avatar  avatar  avatar

elm-horizon's Issues

Publish to elm-package

I arrived here looking for an Elm package managing the Horizon library. After reading the doc, I have to say I'm not disapointed at all. I ran your exemples, but I can't find your package on package.elm-lang.org.

I understand that your library is not ready yet, according your disclaimer in the readme. But, could you still publish a (beta?) version to the package manager ? This way, people could easily try this library, and contribute if they can/need to.

I'd be glad to help you build a great library around Horizon but I can't find a way to try this library into my own projects.


EDIT: I'm confused, I'm still learning Elm. It seems that package including ports can't be plublished to the official package hub. So, how packages like this one can be shared and installed ? Should I manually copy and paste your source code into my own application ? It sounds crazy.

Unable to build the src/Horizon.elm

Hi,

I wanted to play a little bit with Horizon and Elm and stumble upon your library. I cloned the repo and run npm start, but the elm-live gave me the compiler error. So I try to compile it with elm-make and I've got the same error:

`bash-3.2$ elm-make src/Horizon.elm
-- DOCUMENTATION ERROR ----------------------------------------- src/Horizon.elm

You must have a documentation comment between the module declaration and the
imports.

26| import Json.Decode as Json exposing (Decoder)
^
Learn more at http://package.elm-lang.org/help/documentation-format
`

I find out, that you need to have the documentation when you are exposing the functions. Am I doing something wrong or am I missing something?

Thanks

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.