Skip to content

Commit e3beb19

Browse files
committed
init
0 parents  commit e3beb19

26 files changed

+31278
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
npm-debug.log

.jshintrc

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"node": true,
3+
"esnext": true,
4+
"bitwise": true,
5+
"camelcase": true,
6+
"curly": true,
7+
"eqeqeq": true,
8+
"immed": true,
9+
"indent": 2,
10+
"latedef": true,
11+
"newcap": true,
12+
"noarg": true,
13+
"quotmark": "single",
14+
"undef": true,
15+
"unused": true,
16+
"strict": true
17+
}

Gruntfile.js

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
module.exports = function (grunt) {
2+
require('load-grunt-tasks')(grunt)
3+
4+
var INPUT_PATH = 'app/index.js';
5+
var OUTPUT_PATH = './dist/javascripts/marty-devtools-jig.js';
6+
7+
grunt.registerTask('test', 'karma');
8+
grunt.registerTask('default', 'concurrent:serve');
9+
grunt.registerTask('release', ['browserify:release', 'exorcise', 'uglify:release']);
10+
11+
grunt.initConfig({
12+
nodemon: {
13+
serve: {
14+
script: './bin/www'
15+
}
16+
},
17+
concurrent: {
18+
serve: {
19+
tasks: ['browserify:watch', 'nodemon:serve'],
20+
options: {
21+
logConcurrentOutput: true
22+
}
23+
}
24+
},
25+
karma: {
26+
unit: {
27+
configFile: 'karma.conf.js'
28+
}
29+
},
30+
browserify: {
31+
release: browserifyOptions(),
32+
watch: browserifyOptions({
33+
watch: true,
34+
debug: true
35+
}),
36+
},
37+
exorcise: {
38+
bundle: {
39+
files: {
40+
'./dist/javascripts/marty-devtools-jig.map': [OUTPUT_PATH]
41+
}
42+
}
43+
},
44+
uglify: {
45+
release: {
46+
options: {
47+
sourceMap: true,
48+
sourceMapIncludeSources: true,
49+
sourceMapIn: 'dist/javascripts/marty-devtools-jig.map'
50+
},
51+
files: {
52+
'dist/javascripts/marty-devtools-jig.min.js': ['dist/javascripts/marty-devtools-jig.js']
53+
}
54+
}
55+
}
56+
});
57+
58+
function browserifyOptions(options) {
59+
options || (options = {});
60+
61+
return {
62+
src: [INPUT_PATH],
63+
dest: OUTPUT_PATH,
64+
options: {
65+
transform: ['reactify', 'envify'],
66+
watch: !!options.watch,
67+
keepAlive: !!options.watch,
68+
browserifyOptions: {
69+
debug: !!options.debug
70+
}
71+
}
72+
};
73+
}
74+
};

Makefile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
BIN = ./node_modules/.bin
2+
3+
.PHONY: bootstrap start;
4+
5+
start: bootstrap
6+
@grunt
7+
8+
bootstrap: package.json
9+
@npm install

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#marty devtools jig
2+
3+
##Quick start
4+
5+
``
6+
npm install # Install all dependencies
7+
npm start # Run the app
8+
``
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var Marty = require('marty');
2+
var FooConstants = require('../constants/fooConstants');
3+
4+
var FooServerActionCreators = Marty.createActionCreators({
5+
addFoo: FooConstants.ADD_FOO(function (foo) {
6+
this.dispatch(foo);
7+
})
8+
});
9+
10+
module.exports = FooServerActionCreators;

app/actions/testActionCreators.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
var Marty = require('marty');
2+
var FooHttpAPI = require('../apis/fooHttpAPI');
3+
var FooConstants = require('../constants/fooConstants');
4+
var TestConstants = require('../constants/testConstants');
5+
6+
var TestActionCreators = Marty.createActionCreators({
7+
createFoo: FooConstants.CREATE_FOO(function (foo) {
8+
return FooHttpAPI.createFoo(foo);
9+
}),
10+
noDispatch: TestConstants.NO_DISPATCH(function (foo, bar) {
11+
console.log('NO_DISPATCH', arguments);
12+
}),
13+
dispatch: TestConstants.DISPATCH(function (foo, bar) {
14+
console.log('DISPATCH', arguments);
15+
}),
16+
promiseThenDispatch: TestConstants.PROMISE_THEN_DISPATCH(function (foo, bar) {
17+
console.log('PROMISE_THEN_DISPATCH', arguments);
18+
}),
19+
dispatchThenPromise: TestConstants.DISPATCH_THEN_PROMISE(function (foo, bar) {
20+
console.log('DISPATCH_THEN_PROMISE', arguments);
21+
}),
22+
fail: TestConstants.FAIL(function (foo, bar) {
23+
console.log('FAIL', arguments);
24+
}),
25+
promiseFail: TestConstants.PROMISE_FAIL(function (foo, bar) {
26+
console.log('PROMISE_FAIL', arguments);
27+
}),
28+
noStores: TestConstants.NO_STORES(function (foo, bar) {
29+
console.log('NO_STORES', arguments);
30+
}),
31+
oneStore: TestConstants.ONE_STORE(function (foo, bar) {
32+
console.log('ONE_STORE', arguments);
33+
}),
34+
multipleStores: TestConstants.MULTIPLE_STORES(function (foo, bar) {
35+
console.log('MULTIPLE_STORES', arguments);
36+
}),
37+
singleComponent: TestConstants.SINGLE_COMPONENT(function (foo, bar) {
38+
console.log('SINGLE_COMPONENT', arguments);
39+
}),
40+
multipleComponents: TestConstants.MULTIPLE_COMPONENTS(function (foo, bar) {
41+
console.log('MULTIPLE_COMPONENTS', arguments);
42+
}),
43+
failInActionHandler: TestConstants.FAIL_IN_ACTION_HANDLER(function (foo, bar) {
44+
console.log('FAIL_IN_ACTION_HANDLER', arguments);
45+
}),
46+
failInComponent: TestConstants.FAIL_IN_COMPONENT(function (foo, bar) {
47+
console.log('FAIL_IN_COMPONENT', arguments);
48+
})
49+
});
50+
51+
module.exports = TestActionCreators;

app/apis/fooHttpAPI.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var Marty = require('marty');
2+
var FooServerActionCreators = require('../actions/fooServerActionCreators');
3+
4+
var FooHttpAPI = Marty.createHttpAPI({
5+
getById: function (id) {
6+
return this.get('/api/foos/' + id).then(function (foo) {
7+
return FooServerActionCreators.addFoo(foo);
8+
});
9+
},
10+
createFoo: function (foo) {
11+
return this.post('/api/foos', { body: foo }).then(function (foo) {
12+
return FooServerActionCreators.addFoo(foo);
13+
});
14+
},
15+
deleteFoo: function (foo) {
16+
return this.post('/api/foos');
17+
}
18+
});
19+
20+
module.exports = FooHttpAPI;

app/components/foo.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
var React = require('react');
2+
var Marty = require('marty');
3+
var FooStore = require('../stores/fooStore');
4+
5+
var FooState = Marty.createStateMixin({
6+
listenTo: [FooStore],
7+
getState: function () {
8+
return {
9+
foo: FooStore.getById(this.props.id)
10+
};
11+
}
12+
});
13+
14+
var Foo = React.createClass({
15+
mixins: [FooState],
16+
render: function () {
17+
return this.state.foo.when({
18+
pending: function () {
19+
return <div className='loading'>Loading</div>;
20+
},
21+
error: function (error) {
22+
return <div className='error'>{error.message}</div>;
23+
},
24+
done: function (foo) {
25+
return <div className='foo'>{foo}</div>;
26+
}
27+
});
28+
}
29+
});
30+
31+
module.exports = Foo;

app/components/home.js

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/** @jsx React.DOM */
2+
3+
var React = require('react');
4+
var _ = require('underscore');
5+
var str = require('underscore.string');
6+
var Input = require('react-bootstrap/Input');
7+
var Panel = require('react-bootstrap/Panel');
8+
var Button = require('react-bootstrap/Button');
9+
var TestConstants = require('../constants/testConstants');
10+
var ButtonToolbar = require('react-bootstrap/ButtonToolbar');
11+
var TestActionCreators = require('../actions/testActionCreators');
12+
13+
var Home = React.createClass({
14+
render: function () {
15+
return (
16+
<div className="home">
17+
<Panel header="Create Action">
18+
<form>
19+
<Input ref="actionType" type="select" label="Action Types" value={this.state.actionType}>
20+
{this.state.actionTypes.map(function (type) {
21+
return <option value={type}>{type}</option>;
22+
})}
23+
</Input>
24+
<Input ref="arguments" type="text" label="Arguments" onChange={this.updateArguments} value={this.state.args}/>
25+
<ButtonToolbar className="pull-right">
26+
<Button onClick={this.createRandomAction}>Create random action</Button>
27+
<Button bsStyle="primary" onClick={this.createAction}>Create action</Button>
28+
</ButtonToolbar>
29+
</form>
30+
</Panel>
31+
</div>
32+
);
33+
},
34+
updateArguments: function () {
35+
this.setState({
36+
args: this.refs.arguments.getValue()
37+
});
38+
},
39+
createRandomAction: function () {
40+
var types = this.state.actionTypes;
41+
var randomType = types[Math.floor(Math.random()*types.length)];
42+
43+
this.setState({ actionType: randomType });
44+
this.createAction();
45+
},
46+
createAction: function () {
47+
var constant = this.refs.actionType.getValue();
48+
var actionType = str.camelize(constant.toLowerCase());
49+
var arguments = eval('[' + this.refs.arguments.getValue() + ']');
50+
var actionCreator = TestActionCreators[actionType];
51+
52+
if (actionCreator) {
53+
actionCreator.apply(TestActionCreators, arguments);
54+
} else {
55+
console.log('Could not find action creator for ' + constant + ' (' + actionType + ')');
56+
}
57+
},
58+
getInitialState: function () {
59+
return this.getState();
60+
},
61+
getState: function () {
62+
return {
63+
actionTypes: actionTypes(),
64+
args: "'foo', 1, 'bar'"
65+
};
66+
67+
function actionTypes() {
68+
return _.values(TestConstants).map(function (constants) {
69+
return constants.type;
70+
});
71+
}
72+
}
73+
});
74+
75+
module.exports = Home;

app/constants/fooConstants.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var Marty = require('marty');
2+
3+
var FooConstants = Marty.createConstants([
4+
'ADD_FOO',
5+
'CREATE_FOO'
6+
]);
7+
8+
module.exports = FooConstants;

app/constants/testConstants.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var Marty = require('marty');
2+
3+
var TestConstants = Marty.createConstants([
4+
'NO_DISPATCH',
5+
'DISPATCH',
6+
'PROMISE_THEN_DISPATCH',
7+
'DISPATCH_THEN_PROMISE',
8+
'FAIL',
9+
'PROMISE_FAIL',
10+
'NO_STORES',
11+
'ONE_STORE',
12+
'MULTIPLE_STORES',
13+
'SINGLE_COMPONENT',
14+
'MULTIPLE_COMPONENTS',
15+
'FAIL_IN_ACTION_HANDLER',
16+
'FAIL_IN_COMPONENT'
17+
]);
18+
19+
module.exports = TestConstants;

app/index.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/** @jsx React.DOM */
2+
3+
var React = require('react');
4+
var Marty = require('marty');
5+
var Router = require('./router');
6+
7+
window.React = React; // For React DevTools
8+
window.Marty = Marty; // For Marty Developer Tools
9+
10+
if (process.env.NODE_ENV !== 'test') {
11+
Router.run(function (Handler, state) {
12+
React.render(<Handler {...state.params} />, document.getElementById('app'));
13+
});
14+
}

app/router.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/** @jsx React.DOM */
2+
3+
var React = require('react');
4+
var Router = require('react-router');
5+
var Route = Router.Route;
6+
7+
var routes = [
8+
<Route name="home" path="/" handler={require('./components/home')} />
9+
];
10+
11+
module.exports = Router.create({
12+
routes: routes,
13+
location: Router.HistoryLocation
14+
});

0 commit comments

Comments
 (0)