Skip to content

Commit 909bc2d

Browse files
committed
real babel build
1 parent fa68007 commit 909bc2d

File tree

5 files changed

+1997
-65
lines changed

5 files changed

+1997
-65
lines changed

Components.js

Lines changed: 120 additions & 59 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Components.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
"scrollmonitor": "^1.0.13"
1111
},
1212
"devDependencies": {
13-
"babel-core": "^6.18.0",
14-
"babel-loader": "^6.2.6",
15-
"babel-plugin-transform-object-assign": "^6.8.0",
16-
"babel-preset-es2015": "^6.18.0",
17-
"babel-preset-react": "^6.16.0",
13+
"babel-cli": "^6.18.0",
14+
"babel-core": "^6.2.1",
15+
"babel-preset-es2015": "^6.3.13",
16+
"babel-preset-react": "^6.3.13",
1817
"babel-preset-stage-0": "^6.16.0"
1918
},
2019
"scripts": {
21-
"test": "echo \"Error: no test specified\" && exit 1"
20+
"test": "echo \"Error: no test specified\" && exit 1",
21+
"build": "babel ./src/Components.js -o ./Components.js --source-maps"
2222
},
2323
"repository": {
2424
"type": "git",
@@ -28,6 +28,13 @@
2828
"scrolling",
2929
"parallax"
3030
],
31+
"babel": {
32+
"presets": [
33+
"es2015",
34+
"react",
35+
"stage-0"
36+
]
37+
},
3138
"author": "Stu Kabakoff <sakabako@gmail.com>",
3239
"license": "MIT",
3340
"bugs": {

src/Components.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
4+
import parallax from './index';
5+
6+
export const ParallaxRoot = (Component) => class ParallaxRoot extends React.Component {
7+
constructor () {
8+
super();
9+
this.state = {root: null};
10+
}
11+
12+
componentDidMount () {
13+
var el = ReactDOM.findDOMNode(this);
14+
this.setState({
15+
root: parallax.create(el, this.props.parallaxOffsets)
16+
});
17+
}
18+
19+
render () {
20+
return (<Component {...this.props} parallaxRoot={this.state.root} />);
21+
}
22+
};
23+
24+
export class ParallaxItem extends React.Component {
25+
26+
initializeParallax (parallaxRoot) {
27+
var el = ReactDOM.findDOMNode(this);
28+
if (this.props.speed) {
29+
parallaxRoot.add(el, this.props.speed);
30+
} else {
31+
var options = {
32+
start: {},
33+
end: {},
34+
easing: {}
35+
};
36+
Object.keys(this.props).forEach((prop) => {
37+
var keyArray = prop.split('-');
38+
var mainKey = keyArray[0];
39+
var childKey = keyArray[1];
40+
41+
switch (mainKey) {
42+
case 'start':
43+
case 'end':
44+
case 'easing':
45+
options[mainKey] = options[mainKey] || {};
46+
options[mainKey][childKey] = this.props[prop];
47+
}
48+
});
49+
parallaxRoot.add(el, options);
50+
}
51+
}
52+
53+
componentDidMount () {
54+
if (this.props.parallaxRoot) {
55+
this.initializeParallax(this.props.parallaxRoot);
56+
}
57+
}
58+
59+
componentWillReceiveProps (newProps) {
60+
if (newProps.parallaxRoot && !this.props.parallaxRoot) {
61+
this.initializeParallax(newProps.parallaxRoot);
62+
}
63+
}
64+
65+
render () {
66+
return (<div className={this.props.className || ''} data-parallax-item>
67+
{this.props.children}
68+
</div>);
69+
}
70+
}

0 commit comments

Comments
 (0)