• This repository has been archived on 08/May/2021
  • Stars
    star
    131
  • Rank 275,867 (Top 6 %)
  • Language
    JavaScript
  • Created over 11 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Thorax Seed


NOTICE:

This repository has been archived and is not supported.

No Maintenance Intended


NOTICE: SUPPORT FOR THIS PROJECT HAS ENDED

This projected was owned and maintained by Walmart. This project has reached its end of life and Walmart no longer supports this project.

We will no longer be monitoring the issues for this project or reviewing pull requests. You are free to continue using this project under the license terms or forks of this project at your own risk. This project is no longer subject to Walmart's bug bounty program or other security monitoring.

Actions you can take

We recommend you take the following action:

  • Review any configuration files used for build automation and make appropriate updates to remove or replace this project
  • Notify other members of your team and/or organization of this change
  • Notify your security team to help you evaluate alternative options

Forking and transition of ownership

For security reasons, Walmart does not transfer the ownership of our primary repos on Github or other platforms to other individuals/organizations. Further, we do not transfer ownership of packages for public package management systems.

If you would like to fork this package and continue development, you should choose a new name for the project and create your own packages, build automation, etc.

Please review the licensing terms of this project, which continue to be in effect even after decommission.


The Thorax Seed contains a blank Thorax + Lumbar project that you can download and clone to start building your app.

To report issues or submit pull requests on Thorax itself visit the core library repository.

From Zero to Todos

The Thorax intro screencast demonstrates how to build a simple todo list in a few minutes. It also shows the optional Thorax Inspector Chrome Extension. To start from scratch and build your own you'll need git and Node installed on your system. You'll then need to download or clone this repository:

git clone git://github.com/walmartlabs/thorax-seed.git

Once your clone is complete, change directories into your cloned seed and run:

npm install

This may take a minute. Note that all of the dependencies are specific to making it easier to build, run and test your app. Once your app is written it can be deployed in any environment. Once npm install is finished you can start your app:

npm start

Your project is ready to run and a browser window will be opened with the running app. You'll see that nothing at all is there since it's a blank project.

File Structure

  • bower.json : Dependencies of the project, if you need to add or remove libraries from your application, edit this file
  • Gruntfile.js : Your friendly Grunt configuration file, npm start will run the default task specified in this file
  • js : All of your application code lives in here
  • lumbar.json : A config containing all of the routes and files that compose your application
  • package.json : Standard npm config file, only needed while still developing your app
  • public : Will be served as the root directory by the server
  • public/modules : Your generated application code, this folder should generally not be checked into git
  • stylesheets : Generally speaking your styles should be application wide (in base.css) or split up per module
  • tasks : Any extra grunt tasks, including the scaffolding
  • templates : Handlebars templates, if a template shares the name / path as a view it will be auto assigned as the template property of the view

Scaffolding

The seed comes with some simple code generation tools that will automatically create files, folders and update your lumbar.json file. To run the code generation tools you first need the grunt-cli:

npm install -g grunt-cli

Once you've got that installed you can run any of the following commands:

  • grunt generate:module:moduleName
  • grunt generate:view:moduleName/viewName
  • grunt generate:collection-view:moduleName/viewName
  • grunt generate:model:moduleName/modelName
  • grunt generate:collection:moduleName/collectionName
  • grunt generate:router:moduleName
  • grunt generate:stylesheet:moduleName

To generate your first view run:

grunt generate:view:todos/index

In addition to modifying lumbar.json a number of files will be created:

  • js/views/todos/index.js
  • templates/todos/index.handlebars

It will also initialize a todos module since it doesn't exist yet. This will in turn create:

  • js/routers/todos.js
  • stylesheets/todos.css

Modules and lumbar.json

A Lumbar module is composed of routes (to be passed to Backbone.Routers), stylesheets and JavaScripts. When a route is visited the scripts and styles associated with the module will be loaded. After running the generate:view task your lumbar.json should look like this:

{
  "mixins": [
    "node_modules/lumbar-loader",
    "node_modules/thorax",
    "config/base.json"
  ],
  "modules": {
    "todos": {
      "routes": {},
      "scripts": [
        "js/routers/todos.js",
        "js/views/todos/index.js"
      ],
      "styles": [
        "stylesheets/todos.css"
      ]
    }
  },
  "templates": {
    "js/init.js": [
      "templates/application.handlebars"
    ]
  }
}

mixins loads up the base configurations for the project. To edit what libraries (jQuery / Bootstrap, etc) are included in the project open up bower.json. The templates hash defines what templates map to a given view. An entry only needs to be added if the name of a view doesn't match the name of a template. For instance, the generator created js/views/todos/index.js and templates/todos/index.js, but it doesn't need to be defined here as the names match.

Since all routes are specified in lumbar.json, to create our first route it needs to be added there so we will create an empty (root) route pointing at an index method:

"modules": {
  "todos": {
    "routes": {
      "": "index"
    },
    ...

In js/routers/todos.js we will then implement the method:

new (Backbone.Router.extend({
  routes: module.routes,
  index: function() {

  }
}));

Note that module.routes is automatically made available and will contain the hash of routes specified in lumbar.json for the todos module.

Application and Views

The Application object contains a number of subclasses defined in the js folder:

  • js/view.js contains Application.View descends from Thorax.View
  • js/collection.js contains Application.Collection descends from Thorax.Collection
  • js/model.js contains Application.Model descends from Thorax.Model

Any application specific methods can be defined in those files.

To place the first view on your page take a look at js/views/todos/index.js:

Application.View.extend({
  name: "todos/index"
});

When a view class is created with extend that has name property it will automatically be available on the Application.Views hash:

Application.Views["todos/index"]

Any template with the same name will also automatically be set as the template property, in this case templates/todos/index.handlebars will be automatically set as the template property.

The Application object also serves as our root view and its el is already attached to the page. It is an instance of Thorax.LayoutView which is meant to display a single view at a time and has a setView method. In js/routers/todos.js we can call:

index: function() {
  var view = new Application.Views["todos/index"]({});
  Application.setView(view);
}

Update templates/todos/index.handlebars with some content to see that it's displaying properly.

Rendering a Collection

To implement a todos list we need to create a collection and set it on the view. Unlike a Backbone.View instance a Thorax.View (and therefore Application.View) instance does not have an options object. All properties passed to the constructor are set on the instance and also become available inside of the handlebars template.

Our index method in js/routers/todos.js should look like:

index: function() {
  var collection = new Application.Collection([{
    title: 'First Todo',
    done: true
  }]);
  var view = new Application.Views["todos/index"]({
    collection: collection
  });
  Application.setView(view);
}

To display the collection we will edit templates/todos/index.handlebars and use the collection helper which will render the block for each model in the collection setting model.attributes as the context inside the block. A tag option may be specified to define what type of HTML tag will be used when creating the collection element:

{{#collection tag="ul"}}
  <li>{{title}}</li>
{{/collection}}

Since we want to be able to mark our todos as done and add new ones, we will add a checkbox to each item in the collection and a form to make new items at the bottom. Our templates/todos/index.handlebars should now look like:

{{#collection tag="ul"}}
  <li {{#done}}class="done"{{/done}}>
    <input type="checkbox" {{#done}}checked{{/done}}>
    {{title}}
  </li>
{{/collection}}
<form>
  <input name="title">
  <input type="submit" value="Add">
</form>

Lastly add an associated style in stylesheets/todos.css:

.done {
  text-decoration: line-through;
}

View Behaviors

In order to add new items to the list we should listen to the submit event on form elements in our view. We can use the events hash in js/views/todos/index.js:

"submit form": function(event) {
  event.preventDefault();
  var attrs = this.serialize();
  this.collection.add(attrs);
  this.$('input[name="title"]').val('');
}

The serialize method will return a hash of all attributes in form elements on the page. Since we had an input with a name of title attrs will be set to: {title: "your todo"}. When using the collection helper or a CollectionView Thorax adds, removes and updates views in the collection as appropriate, so once we add a new model to the collection the view will automatically update.

'change input[type="checkbox"]': function(event) {
  var model = $(event.target).model();
  model.set({done: event.target.checked});
}

We also need to listen for a change in a checkbox so we can mark a model as done. Thorax extends the jQuery or Zepto $ object with three methods: $.view, $.model and $.collection. They will retrieve closest bound object to an element. In this case a model was automatically bound to the li tag passed into the collection helper in the template. Now that we have a reference to the model we can update it and the view will automatically update.

Our finished js/views/todos.js file should look like:

Application.View.extend({
  name: "todos/index",
  events: {
    "submit form": function(event) {
      event.preventDefault();
      var attrs = this.serialize();
      this.collection.add(attrs);
      this.$('input[name="title"]').val('');
    },
    'change input[type="checkbox"]': function(event) {
      var model = $(event.target).model();
      model.set({done: event.target.checked});
    }
  }
});

And that's a finished non persistent todo list application! For a more complex todos example see the Thorax + Lumbar TodoMVC example

More Seeds

  • Todos : The project in the state at the end of the screencast (and described in this document)
  • Mocha : Blank seed with a Mocha test harness setup

More Repositories

1

lacinia

GraphQL implementation in pure Clojure
Clojure
1,821
star
2

thorax

Strengthening your Backbone
JavaScript
1,322
star
3

react-ssr-optimization

React.js server-side rendering optimization with component memoization and templatization
JavaScript
822
star
4

electrode

Electrode - Application Platform on React/Node.js powering Walmart.com
449
star
5

little-loader

A lightweight, IE8+ JavaScript loader
JavaScript
370
star
6

json-to-simple-graphql-schema

Transforms JSON input into a GraphQL schema
JavaScript
283
star
7

eslint-config-defaults

A composable set of ESLint defaults
JavaScript
228
star
8

lumbar

Modular javascript build tool
JavaScript
226
star
9

concord

Concord - workflow orchestration and continuous deployment management
Java
211
star
10

datascope

Visualization of Clojure data structures using Graphviz
Clojure
207
star
11

lacinia-pedestal

Expose Lacinia GraphQL as Pedestal endpoints
Clojure
200
star
12

bigben

BigBen - a generic, multi-tenant, time-based event scheduler and cron scheduling framework
Kotlin
196
star
13

kubeman

The Hero that Kubernetes deserves
TypeScript
164
star
14

system-viz

Graphviz visualization of a component system
Clojure
161
star
15

react-native-orientation-listener

A react-native library for obtaining current device orientation
Java
151
star
16

vizdeps

Visualize Leiningen dependencies using Graphviz
Clojure
131
star
17

mupd8

Muppet
Scala
126
star
18

active-status

Present status of mulitple 'jobs' in a command line tool, using terminal capability codes
Clojure
119
star
19

schematic

Combine configuration with building a Component system
Clojure
104
star
20

easy-fix

easy-fix: run integration tests like unit tests
JavaScript
101
star
21

dyn-edn

Dynamic properties in EDN content
Clojure
96
star
22

fruit-loops

Server-side jQuery API renderer.
JavaScript
88
star
23

generator-thorax

Thorax yeoman generator
JavaScript
87
star
24

walmart-cla

Walmart Contributor License Agreement Information
85
star
25

react-native-cropping

Cropping components for react-native
JavaScript
68
star
26

gozer

Open source library to parse various X12 file formats for retail/supply chain
Java
66
star
27

curved-carousel

An infinitely scrolling carousel with configurable curvature
JavaScript
64
star
28

walmart-api

API wrapper for the public Walmart Labs API
JavaScript
61
star
29

cookie-cutter

An opinionated micro-services framework for TypeScript
TypeScript
58
star
30

mock-server

SPA application debug proxy server
JavaScript
57
star
31

test-reporting

Tiny library to assist with reporting some context when a test fails
Clojure
53
star
32

container-query

A responsive layout helper based on the width of the container
JavaScript
52
star
33

eslint-config-walmart

A set of default eslint configurations, Walmart Labs style.
JavaScript
49
star
34

react-native-platform-visible

A very simple component visibility switch based on Platform
JavaScript
49
star
35

clojure-game-geek

Example source code for the Lacinia tutorial
Clojure
47
star
36

generator-release

Yeoman generator for handling Bower/NPM releases.
JavaScript
45
star
37

babel-plugin-react-cssmoduleify

Babel plugin to transform traditional React element classNames to CSS Modules
JavaScript
45
star
38

costanza

Frontend error tracking toolkit: Own your own domain
JavaScript
36
star
39

zFAM

z/OS-based File Access Manager
Assembly
36
star
40

nightcall

Automated Enumeration Script for Pentesting
Python
33
star
41

cond-let

A useful merge of cond and let
Clojure
30
star
42

static

JavaScript
26
star
43

bolt

[DEPRECATED] an opinionated meta task runner for components.
JavaScript
24
star
44

shared-deps

Leiningen plugin to allow sub-modules to more easily share common dependencies
Clojure
24
star
45

ridicule

Mocking everything
JavaScript
22
star
46

linearroad

Walmart version of the Linear Road streaming benchmark.
Java
22
star
47

backbone-historytracker

Backbone plugin for navigation direction tracking
JavaScript
22
star
48

zECS

z/OS-based Enterprise Cache Service
COBOL
21
star
49

pulsar

Text-based dashboard for Elixir CLIs
Elixir
20
star
50

react-native-image-progressbar

An image based progress bar
JavaScript
20
star
51

zUID

z/OS-based Unique Identifier generator
Assembly
17
star
52

layout

A simple responsive layout helper
CSS
17
star
53

showcase-template

A starter template for a showcase of React components
CSS
16
star
54

anomaly-detection-walmart

Python
15
star
55

grunt-release-component

Grunt release helper for bower components
JavaScript
15
star
56

partnerapi_sdk_dotnet

Walmart Partner API SDK for .NET
C#
14
star
57

concord-website

Documentation website source code for Concord
JavaScript
14
star
58

circus

External Webpack Component Plugin
JavaScript
13
star
59

concord-plugins

Java
12
star
60

strati-functional

A lightweight collection of functional classes used to complement core Java.
Java
12
star
61

thorax-boilerplate

A boilerplate project for Thoroax
JavaScript
11
star
62

nocktor

nocktor - your nock doctor
JavaScript
11
star
63

LinearGenerator

Reworked data generator for LinearRoad streaming benchmark that no longer needs mitsim or any database.
Java
9
star
64

getting-started

How to get started with the WalmartLabs API and tooling
9
star
65

json-patchwork

JavaScript
9
star
66

object-diff

A Go library implementing object wise diff and patch.
Go
8
star
67

small-world-graph

Graphing as in Data
C++
8
star
68

chai-shallowly

A chai assertion plugin for enzyme.
JavaScript
8
star
69

typeahead.js-legacy

typeahead.js is a fast and fully-featured autocomplete library
JavaScript
8
star
70

child-pool

child_process pool implementation
JavaScript
7
star
71

thorax-todos

JavaScript
6
star
72

hula-hoop

Server-side rendering components for Thorax + Hapi stacks.
JavaScript
6
star
73

apache-http-client

A Clojure ring compatible http interface for Apache HttpClient
Clojure
5
star
74

lumbar-loader

JavaScript
5
star
75

krabby

JavaScript
4
star
76

js-conceptualizer

JS Conceptualizer is a bit of client-side Javascript that parses out concepts, particularly proper nouns, from HTML on a web page.
JavaScript
4
star
77

babel-plugin-i18n-id-hashing

Namespace the ID of React-Intl keys
JavaScript
4
star
78

express-example

A crazy simple example of using the Walmart API with express
JavaScript
4
star
79

wml-coding-std

A module for keeping consistent JS coding standards at WML
JavaScript
3
star
80

nativedriver

native driver for UI automation
Objective-C
3
star
81

was

Go
3
star
82

hapi-example

A crazy simple example of using the Walmart API with hapi
JavaScript
3
star
83

lumbar-long-expires

Long expires cache buster plugin for Lumbar
JavaScript
3
star
84

component-scan

A component scanner for React
JavaScript
3
star
85

scanomatic-server

Scan-O-Matic Node Server
JavaScript
3
star
86

hadoop-openstack-swifta

hadoop-openstack-swifta
Java
3
star
87

thorax-rails

Ruby
3
star
88

SDJSBridge

Native/Hybrid Javascript Bridge
Objective-C
2
star
89

cordova-starter-kit

A starter kit for using Cordova and the Walmart API
JavaScript
2
star
90

priorityY

Priority Based Connected Components
Python
2
star
91

bolt-standard-flux

electrode bolt standard configs and tasks for flux architecture.
JavaScript
1
star
92

bolt-cli

[DEPRECATED] bolt command line interface.
JavaScript
1
star
93

github-util

Github utility methods.
JavaScript
1
star
94

circus-stylus

Stylus linker for Circus components
JavaScript
1
star
95

apidocs

HTML
1
star
96

lumbar-tester

Unit testing plugin for Lumbar
JavaScript
1
star
97

SDUserActivity

An simplified interface for NSUserActivity for apps that want to participate in handoff.
Objective-C
1
star
98

walmartlabs.github.io

Helper to redirect to code.walmartlabs.com
HTML
1
star
99

BurpSuiteDynamicSessionTracker

BurpSuite extension for tracking and manipulating dynamic session cookies
Java
1
star
100

phoenix-build

Common build libraries for Phoenix projects
JavaScript
1
star