Git Product home page Git Product logo

starter-kit's Introduction

Unicorn Standard Starter Kit

This starter kit provides you with the code and conventions you need to get straight into building your React/Redux based app.

Happiness is six lines away

Prerequisites: node.js and git

git clone https://github.com/unicorn-standard/starter-kit.git your-repo-name
cd your-repo-name
npm install
npm start
npm run open # (from a different console window, otherwise open localhost:3000)

Presto, you've got a ready-to-customise application!

Unicorn Standard Starter Kit

Why use Unicorn Standard Starter Kit?

  • Your directory structure is sorted as soon as you git clone
  • ES6 compilation and automatic-reloading development server are configured for you with webpack and Babel
  • Redux is an incredibly simple way of modelling your data, with great community support
  • React is an incredibly simple way of rendering your views, and is maintained by Facebook
  • Simple uniloc-based routing is included - easy to understand, and easy to customize
  • The Pacomo CSS conventions eliminate bugs caused by conflicting styles
  • The actors pattern allows you to easily react to changes on your store without forcing a re-render
  • Your redux store is already configured with navigation, data and view models
  • Comes with views, layouts and reducers for a simple document editor!

Getting Started

Put your name on it

  • Update name, desription and author in package.json
  • Update app title in src/index.html
  • Restart the dev server (make sure to do this after any changes to src/index.html)

Make sure your editor is happy

  • Setup ES6 syntax highlighting on extensions .js and .jsx (see babel-sublime)

Start building

  • Add a route to src/constants/ROUTES.js
  • Add a nav menu item for your route in src/components/ApplicationLayout.jsx
  • Add a component for your route in src/components
  • Add reducers and actions for your component's view model in src/actions and src/reducers/view
  • Add any data models which your component reqiures in src/reducers/data
  • Add a container to map your store's state and dispatch to component props in src/containers
  • Configure your route in src/Application.jsx
  • Bask in the glory of your creation
  • Don't forget to commit your changes and push to Bitbucket or GitHub!

Show your friends

  • Run gulp dist to output a web-ready build of your app to dist

Structure

Entry point

main.js is the entry point to your application. It defines your redux store, handles any actions dispatched to your redux store, handles changes to the browser's current URL, and also makes an initial route change dispatch.

Most of the above will be obvious from a quick read through main.js - if there is one thing which may strike you as "interesting", it'll be the block which handles actors.

Actors

Read the introduction to actors

Each time your store's state changes, a sequence of functions are called on the current state of your store. These functions are called actors.

There is one important exception to this rule: actors will not be called if main.js is currently in the midst of calling the sequence from a previous update. This allows earlier actors in a sequence to dispatch actions to the store, with later actors in the sequence receiving the updated state.

The code which accomplishes this is very small:

let acting = false
store.subscribe(function() {
  // Ensure that any action dispatched by actors do not result in a new
  // actor run, allowing actors to dispatch with impunity.
  if (!acting) {
    acting = true

    for (let actor of actors) {
      actor(store.getState(), store.dispatch.bind(store))
    }

    acting = false
  }
})

The actor is defined in src/actors/index.js. By default, it runs the following sequence:

  • redirector - dispatch a navigation action if the current location should redirect to another location
  • renderer - renders your component with React

Model

Your model (i.e. reducers and actions) is pre-configured with three parts:

Navigation

The navigation state holds the following information:

  • location is the object which your ROUTES constant's lookup function returns for the current URL. With the default uniloc-based ROUTES object, this will have a string name property, and an options object containing any route parameters.
  • transitioning is true if a navigation start action has been dispatched, but the browser hasn't changed URL yet

Data

The data state can be thought of as the database for your application. If your application reads data from a remote server, it should be stored here. Any metadata should also be stored here, including the time it was fetched or its current version number.

View

The view state has a property for each of the view's in your app, holding their current state. For example, form state should be stored in the view models.

Directories

  • src/actions - Redux action creators
  • src/actors - Handle changes to your store's state
  • src/components - React components, stateless where possible
  • src/constants - Define stateless data
  • src/containers - Unstyled "smart" components which take your store's state and dispatch, and possibly navigation location, and pass them to "dumb" components
  • src/reducers - Redux reducers
  • src/static - Files which will be copied across to the root directory on build
  • src/styles - Helpers for stylesheets for individual components
  • src/utils - General code which isn't specific to your application
  • src/validators - Functions which take an object containing user entry and return an object containing any errors

Other directories:

  • build - Intermediate files produced by the development server. Don't touch these.
  • dist - The output of gulp dist, which contains your distribution-ready app.
  • config/environments - The build system will assign one of these to the environment module, depending on the current build environment.

Main application files:

  • src/Application.jsx - Your application's top-level React component
  • src/index.html - The single page for your single page application
  • src/main.js - The application's entry point
  • src/main.less - Global styles for your application

Main build files:

  • gulpfile.babel.js - Build scripts written with gulp
  • webpack.config.js - Webpack configuration

TODO

  • Watch static and index.html for changes and copy them across to build when appropriate

starter-kit's People

Contributors

hasansoydabas avatar jamesknelson avatar jokeyrhyme avatar mr-wildcard avatar roryokane 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

starter-kit's Issues

A question

I apologize for leaving this here but I wasn't sure how to best get in contact with you.

I'm looking over this repo and I've followed some of your prior guides to upgrading to Babel 6+. I just did this upgrade on our code base and I'm running into an import issue. Basically we export our React (and other ES6 modules) as such:

export default Foo;

Then, we would import them as such:

import Foo from 'foo';

This all worked fine in Babel <6 but after the upgrade I see my objects as as having a default property and the actual object being exported is in that property. This causes me to have to change EVERY import in our codebase to:

import {default as Foo} from 'foo';

In looking at your code in this repo I see you're doing none of that. Do I really need to go through and change all my imports like this and moving forward have that be the proper way of importing my modules or am I missing something larger here?

Thanks for any time you take responding to this. You're not obligated but I do appreciate any help you could offer.

SyntaxError: Unexpected token import

Running into this when downloaded. I've installed everythingI can think of with regards to babel but I've just hit a wall with my knowledge.

I'm on node 5.5.0, npm 3.6.0.

gulp serve

[09:33:16] Requiring external module babel-core/register
/Users/re/Documents/Coding/test/gulpfile.babel.js:1
(function (exports, require, module, __filename, __dirname) { import del from "del";
^^^^^^

SyntaxError: Unexpected token import
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:387:25)
at loader (/Users/re/Documents/Coding/test/node_modules/babel-register/lib/node.js:128:5)
at Object.require.extensions.(anonymous function) as .js
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Liftoff.handleArguments

no need for gulp to be installed globally

NPM is clever enough, to find gulp in projects node_modules folder.

Just add a gulp script into scripts section.

{
  "scripts": {
    "start": "gulp serve",
    "open": "gulp open",
    "gulp": "gulp"
  }
}

Now its possible to execute npm run gulp dist without having gulp (or anything else) installed globally. No version conflict between projects anymore. We need to remove global dendencies everywhere.

npm start failing

Hey, this is probably a dumb issue, but I wanted to make you aware of it so other people don't have the same problem.

I'm using nodejs v5.0 and I get the error below. However, 0.12.7 works fine. Looks like I need a harmony flag set somewhere. I'm just not sure the best way to work that into this configuration. Thoughts?

/Users/Trevor/starter-kit/gulpfile.babel.js:1
(function (exports, require, module, __filename, __dirname) { import del from "del";
                                                              ^^^^^^

SyntaxError: Unexpected token import
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:404:25)
    at Object.Module._extensions..js (module.js:432:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Liftoff.handleArguments (/usr/local/lib/node_modules/gulp/bin/gulp.js:116:3)
    at Liftoff.<anonymous> (/usr/local/lib/node_modules/gulp/node_modules/liftoff/index.js:192:16)
    at module.exports (/usr/local/lib/node_modules/gulp/node_modules/liftoff/node_modules/flagged-respawn/index.js:17:3)

npm ERR! Darwin 14.5.0
npm ERR! argv "/Users/Trevor/.nvm/versions/node/v5.0.0/bin/node" "/Users/Trevor/.nvm/versions/node/v5.0.0/bin/npm" "start"
npm ERR! node v5.0.0
npm ERR! npm  v3.3.6
npm ERR! code ELIFECYCLE
npm ERR! @0.1.0 start: `gulp serve`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @0.1.0 start script 'gulp serve'.
npm ERR! This is most likely a problem with the  package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     gulp serve
npm ERR! You can get their info via:
npm ERR!     npm owner ls
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/Trevor/starter-kit/npm-debug.log

batchedSubscribe brokes async dispatches

batchedSubscribe enchants store after applying middlewares. As batchedSubscribe replaces dispatch, async actions based on reduxThunk middleware won't trigger notifications.

Cannot clone

Hi,

I've tried to clone repo but i got this error:

$ git clone [email protected]:unicorn-standard/boilerplate.git unicorn
Cloning into 'unicorn'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Why Gulp?

This project looks interesting, but I'm confused as to why both Webpack and Gulp are in use. Why not use Webpack to produce distribution builds?

Some rookie questions

I am not clear there are source maps being generated as when I look at source files in Chrome devtools I am seeing stuff that has been chewed on a bit, that is no JSX. Am I missing something or does some other command than start do that?

Personally I would be happier if this did not throw Redux and gulp into the mix although I can see some advantages to the latter. I got to this page attempting to get a more pure webpack solution working directly. And so far at least I am well down the flux alt variant path.

gulp serve fails

*[master][~/source/unicorn-trade]$ gulp serve
[12:08:56] Requiring external module babel-register
(node:92796) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
[12:08:56] Using gulpfile ~/source/unicorn-trade/gulpfile.babel.js
[12:08:56] Starting 'serve'...
[12:08:56] Starting 'serve:clean'...
[12:08:56] Finished 'serve' after 5.12 ms
[12:08:56] Finished 'serve:clean' after 12 ms
[12:08:56] Starting 'serve:index'...
[12:08:56] Finished 'serve:index' after 31 ms
[12:08:56] Starting 'serve:static'...
[12:08:56] Finished 'serve:static' after 15 ms
[12:08:56] Starting 'serve:start'...
options.watchDelay is deprecated: Use 'options.watchOptions.aggregateTimeout' instead
[12:08:56] Finished 'serve:start' after 52 ms
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE 0.0.0.0:3000
    at Object.exports._errnoException (util.js:1008:11)
    at exports._exceptionWithHostPort (util.js:1031:20)
    at Server._listen2 (net.js:1253:14)
    at listen (net.js:1289:10)
    at net.js:1399:9
    at _combinedTickCallback (internal/process/next_tick.js:77:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)
*[master][~/source/unicorn-trade]$

switch to CSS-modules via webpack

Would you accept a PR that uses css-modules via the css-loader webpack plugin that you're already using?

This may or may not be a transition from pacomo.

This approach would still have 1 CSS file next to the JSX file for a component, but relies on the build step to give each module its own private CSS class scope. This means you don't need a naming convention.

Clearer documentation for gulpfile.babel.js

While the gulpfile works, it probably could use some clearer documentation. Specifically:

  • Why do we have both dist/serve
  • What do each of the main tasks do
  • What do the index tasks do, why do the different, and how do they do it
  • Why does dist have build and serve have `start?

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.