All data classes in Lanes ultimately derive from the excellent AmpersandState.

Each Lanes application is setup with a base Model and Compoment which extend from Lanes.Models.Base and Lanes.Components.Base respectively. This provides a central place to provide custom functionality.

All files are wrappend in a closure that provides the Lanes, FILE, and the application itself. The FILE object contains information about the file and is used for looking up information relating to the class. For instance models use it for auto-setting their api path.

An example Model

By default the model will use the <Lanes.root_path>/banking/customers endpoint. Each model has a static Collection auto-created.

class Banking.Models.Customer extends Banking.Models.Base
    FILE: FILE

    props:
        id:   {type:"integer",required:true}
        code: {type:"string", required:true}
        balance: {type: "number", default: 0.0}
    associations:
        addresses: { collection: "Address" }

An example Component

Components are simply React compopnents with a few mixins automatically added.

class Banking.Components.Customer extends Banking.Components.Base

    propTypes:
        model: Lanes.PropTypes.Model.isRequired

    onClick: ->
        @model.balance += 100

    render: ->
        <div>
            Hello! {@model.name}, your balance is {@model.balance}
            <button onClick={@buttonClick}>Gimme Money</button>
        </div>

Usage

A bit contrived since Lanes handles all this setup for you

customer = new Banking.Views.Customer
component = React.createElement(Banking.Components.Customer, model: customer)