Giter Club home page Giter Club logo

vrroom's Introduction

vRRoom - Turbo-charged ReasonReact!

A collection of mostly experimental tools and utilities for effective ReasonReact development.

Installation

Run npm install --save glennsl/vrroom and add vrroom to bs-dependencies in bsconfig.json.

Usage

If you're not too afraid of polluting your namespace, the most convenient way to use Vrroom is to open Vrroom at the top of the module. Otherwise, to avoid polluting the namespace, using module V = Vrroom is recommended.

Examples

Control.Map

/* Without Control.Map */
{
  switch noItems {
  | [||] => <Item label="." />
  | items => 
    items |> Array.map(name => <Item label=name />)
          |> ReasonReact.array
  }  
}

/* With Control.Map */
<Control.Map items=noItems empty=<Item label="-"/> >
  ...(name => <Item label=name />)
</Control.Map>

Control.IfSome

/* Without Control.IfSome */
{
  switch maybeError {
  | Some(error) => error |> text
  | None        => nothing
  }
}

/* With Control.IfSome */
<Control.IfSome option=maybeError>
  ...(error => error |> text)
</Control.IfSome>

pure

/* Without pure */
module ItemBefore = {
  let instance = ReasonReact.statelessComponent("Item");
  let make = (~label, _children) => {
    ...instance,
    render: _self =>
      <li> (label |> text) </li>
  }
};

/* With pure */
module Item = {
  let make = pure((render, ~label) => render(
    <li> (label |> text) </li>
  ));
};

See more examples in the examples folder

Documentation

type childless = array(nothing)

Used to indicate and enforce a childless component by making it impossible to add children without circumventing the type system, since nothing is an abstract type with no way to construct a value.

Example:

let make = (_:childless) => ...

let text : string => ReasonReact.reactElement

Alias for Text.string and therefore ReasonReact.string.

Example:

<div> {"Hello!" |> text} </div>

let nothing : ReasonReact.reactElement

Alias for ReasonReact.null.

Example:

<div> {isAwkward ? nothing : text("Hello!")} </div>

let nbsp : ReasonReact.reactElement

Insert a &nbsp; (actually the unicode equivalent since React escapes HTML entities). Useful to avoid some elements mysteriously disappearing when empty (or more likely containing nothing).

Example:

<div> {isAwkward ? nbsp : text("Hello!")} </div>

let pure : (((ReasonReact.reactElement, childless) => ReasonReact.component(ReasonReact.stateless ReasonReact.noRetainedProps, ReasonReact.actionless)) => 'a) => 'a

An experimental convenience function for creating a "functional" stateless component.

Example:

modul Item = {
  let make = pure((render, ~label) => render(
    <li> (label |> text) </li>
  ));
};

module Text

let Text.string : string => ReasonReact.reactElement

Alias for ReasonReact.string.

Example:

<div> {"Hello!" |> Text.string} </div>

let Text.int : int => ReasonReact.reactElement

Would be an alias for ReasonReact.intToElement if it had existed.

Example:

<div> {42 |> Text.int} </div>

let Text.float : float => ReasonReact.reactElement

Would be an alias for ReasonReact.floatToElement if it had existed.

Example:

<div> {4.2 |> Text.float} </div>

let Text.any : _ => ReasonReact.reactElement

Converts anything to a string, then casts it as an element.

Example:

<div> {["Hello", "brother!"] |> Text.any} </div>

module ClassName

let ClassName.join : list(string) => string

Joins a list of strings into a single space-separated string, ignoring empty string.

Example:

<div className=ClassName.join(["button", "primary"])> ... </div>

let ClassName.if_ : (bool, string) => string

Returns the given string if condition is true, otherwise an empty string. Most useful in conjunction with thje join function.

Example:

<div className=ClassName.(join(["button", "s-hover" |> if_(isHovered)]))> ... </div>

let ClassName.fromOption : option(string) => string

Returns the contained string if any, otherwise an empty string. Most useful in conjunction with thje join function.

Example:

<div className=ClassName.(join(["button", maybeError |> fromOption]))> ... </div>

<Fragment> array(ReasonReact.reactElement) </Fragment>

Binding to the standard React Fragment component. Renders its children without a surrounding DOM element.

Example:

<tr> ... </tr>
<Fragment>
  <tr> ... </tr>
  <tr> ... </tr>
</Fragment>
<tr> ... </tr>

<Control.Map items=array('a) ?empty=ReasonReact.reactElement> ...('a => ReasonReact.reactElement) </Control.Map>

Renders each item in items using the given render function, or if the array is empty, the given empty element or nothing if oomitted.

Example:

<Control.Map items=[|"apple", "banana"|] empty=<Item label="-"/> >
  ...(name => <Item label=name />)
</Control.Map>

<Control.MapList items=list('a) ?empty=ReasonReact.reactElement> ...('a => ReasonReact.reactElement) </Control.MapList>

Renders each item in items using the given render function, or if the list is empty, the given empty element or nothing if oomitted.

Example:

<Control.MapList items=["apple", "banana"] empty=<Item label="-"/> >
  ...(name => <Item label=name />)
</Control.MapList>

<Control.If cond=bool> ...(unit => ReasonReact.reactElement) </Control.If>

Renders the element returned by the render function if cond is true, otherwise nothing.

Example:

<Control.If cond=showHello>
    ...(() => "Hello" |> text)
</Control.If>

<Control.IfSome option=option('a)> ...('a => ReasonReact.reactElement) </Control.IfSome>

Calls the render function with the contained item in option if any, and renders the returned element, otherwise nothing.

Example:

<Control.IfSome option=maybeError>
  ...(error => error |> text)
</Control.IfSome>

vrroom's People

Contributors

glennsl avatar idkjs avatar happylinks avatar

Stargazers

Thomas Alcala Schneider avatar Medson Oliveira avatar savi2w avatar Gage Peterson avatar Nathan Hemingway avatar M∎∎r avatar Taras Vozniuk avatar Ezekiel avatar Joseph Price avatar Cem Turan avatar Rusty Key avatar Lan Qingyong avatar Javier Chávarri avatar Juang Wiantoro avatar  avatar  avatar  avatar  avatar Meillet Robin avatar Daniel Mantei avatar Juwan Wheatley avatar Rafa Yepes avatar Alessandro Strada avatar Marcin Dziewulski avatar Daniel Ramirez avatar Gabriel avatar  avatar Juan Bono avatar

Watchers

James Cloos avatar  avatar Juan Bono avatar  avatar

Forkers

happylinks idkjs

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.