Giter Site home page Giter Site logo

cosmos's Introduction

Cosmos Build Status Coverage Status

Cosmos is a React development utility built on top of:

  1. ComponentTree โ€” Serialize and reproduce the state of an entire tree of React components
  2. ComponentPlayground โ€” Minimal frame for loading and testing React components in isolation

Working with ComponentPlayground improves the component design because it surfaces any implicit dependencies. It also forces you to define sane inputs for every component, making them more predictable and easier to debug down the road.

There's no such thing as controllers or pages when working with Cosmos, just components. The UI is a tree of components consisting of a root component and its descendants. Moreover, any component can be loaded full-screen as the root element.

Component Playground

Requirements

  • You should already be using CommonJS modules to structure your code and webpack to bundle your modules for the browser
  • Your React components should be fully encapsulated. They should have no global dependencies and rely exclusively on props for input. Including styles, which means you need to be using style-loader.
  • You must create component fixtures for ComponentPlayground to load. The component and fixture files should be nested as in the folder structure below. See the example repo for a better picture.

Installing

  • Install the Cosmos package through npm npm install cosmos-js
  • Run the ComponentPlayground executable node_modules/.bin/component-playground
  • Open localhost:8989

Under the hood

Running the ComponentPlayground executable will:

  1. Start a webpack dev server, serving an instance of ComponentPlayground at localhost:8989
  2. Scan the current folder for components and fixtures and feed them to ComponentPlayground

The webpack build bundles modules from both the current folder and the Cosmos package. It is currently compatible with React classes, ES6 classes, JSX and CSS/LESS modules. In the future the webpack config should be configurable.

This is the file structure Cosmos expects:

|
+-- components
|   +-- FooComponent.jsx
|   +-- namespace
|   |   +-- BarComponent.jsx
+-- fixtures
|   +-- FooComponent
|   |   +-- default.js
|   |   +-- active.js
|   +-- namespace
|   |   +-- BarComponent
|   |       +-- default.js
|   |       +-- paused.js

If the components and fixtures folders are not siblings, their paths can be specified via cli args:

node_modules/.bin/component-playground --components-path src/components --fixtures-path tests/fixtures

Thank you for your interest!

Join the chat at https://gitter.im/skidding/cosmos

Explore the wiki for more info on the Cosmos project.

cosmos's People

Contributors

adaschevici avatar gitter-badger avatar nighttrax avatar piatra avatar skidding avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

rubythonode

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.