react-scroll-parallax
Advanced tools
Comparing version 1.1.0 to 1.1.1
import React, { Component } from 'react'; | ||
// import PropTypes from 'prop-types'; | ||
import { ParallaxProvider } from 'react-scroll-parallax'; | ||
@@ -7,9 +6,20 @@ import { ParallaxTest } from 'components'; | ||
export default class App extends Component { | ||
// this just serves to test unmount/re-mount ParallaxProvider | ||
state = { | ||
mount: true, | ||
}; | ||
render() { | ||
return ( | ||
<ParallaxProvider> | ||
<ParallaxTest /> | ||
</ParallaxProvider> | ||
<main> | ||
{this.state.mount ? ( | ||
<ParallaxProvider> | ||
<ParallaxTest /> | ||
</ParallaxProvider> | ||
) : ( | ||
<div /> | ||
)} | ||
</main> | ||
); | ||
} | ||
} |
@@ -11,2 +11,4 @@ 'use strict'; | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
/** | ||
@@ -320,10 +322,11 @@ * ------------------------------------------------------- | ||
var id = _createID(); | ||
var element = _extends({ | ||
var newElement = _extends({ | ||
id: id | ||
}, options); | ||
elements.push(element); | ||
var updatedElements = [].concat(_toConsumableArray(elements), [newElement]); | ||
elements = updatedElements; | ||
this.update(); | ||
return element; | ||
return newElement; | ||
}; | ||
@@ -337,10 +340,6 @@ | ||
this.removeElement = function (element) { | ||
// gets the index of the element to update based on id | ||
var index = elements.findIndex(function (el) { | ||
return el.id === element.id; | ||
var updatedElements = elements.filter(function (el) { | ||
return el.id !== element.id; | ||
}); | ||
if (index !== -1) { | ||
elements.splice(index, 1); | ||
} | ||
elements = updatedElements; | ||
}; | ||
@@ -354,14 +353,15 @@ | ||
this.updateElement = function (element, options) { | ||
// gets the index of the element to update based on id | ||
var index = elements.findIndex(function (el) { | ||
return el.id === element.id; | ||
var updatedElements = elements.map(function (el) { | ||
// create element with new options and replaces the old | ||
if (el.id === element.id) { | ||
// update props | ||
el.props = options.props; | ||
} | ||
return el; | ||
}); | ||
// create new element with options and replaces the old | ||
if (index !== -1) { | ||
elements[index] = Object.assign({}, elements[index], options); | ||
elements = updatedElements; | ||
// call update to set attributes and positions based on the new options | ||
this.update(); | ||
} | ||
// call update to set attributes and positions based on the new options | ||
this.update(); | ||
}; | ||
@@ -392,2 +392,3 @@ | ||
_removeParallaxStyles(); | ||
window.ParallaxController = null; | ||
}; | ||
@@ -394,0 +395,0 @@ } |
{ | ||
"name": "react-scroll-parallax", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "React component to create parallax scrolling effects", | ||
@@ -14,3 +14,3 @@ "repository": { | ||
"gh-pages": "NODE_ENV=production webpack --progress --colors", | ||
"test": "jest", | ||
"test": "BABEL_ENV=test jest", | ||
"prettier": "prettier --tab-width 4 --single-quote --trailing-comma es5 --print-width 80 --write \"{src,examples,__tests__}/**/**/**/*.js\"", | ||
@@ -17,0 +17,0 @@ "prepublish": "babel ./src --out-dir ./lib --presets es2015,react,stage-0 --plugins babel-plugin-add-module-exports" |
@@ -22,3 +22,3 @@ import { | ||
// All parallax elements to be updated | ||
const elements = []; | ||
let elements = []; | ||
@@ -327,3 +327,3 @@ // Tracks current scroll y distance | ||
const id = _createID(); | ||
const element = { | ||
const newElement = { | ||
id, | ||
@@ -333,6 +333,7 @@ ...options, | ||
elements.push(element); | ||
const updatedElements = [...elements, newElement]; | ||
elements = updatedElements; | ||
this.update(); | ||
return element; | ||
return newElement; | ||
}; | ||
@@ -346,8 +347,4 @@ | ||
this.removeElement = function(element) { | ||
// gets the index of the element to update based on id | ||
const index = elements.findIndex(el => el.id === element.id); | ||
if (index !== -1) { | ||
elements.splice(index, 1); | ||
} | ||
const updatedElements = elements.filter(el => el.id !== element.id); | ||
elements = updatedElements; | ||
}; | ||
@@ -361,12 +358,15 @@ | ||
this.updateElement = function(element, options) { | ||
// gets the index of the element to update based on id | ||
const index = elements.findIndex(el => el.id === element.id); | ||
const updatedElements = elements.map(el => { | ||
// create element with new options and replaces the old | ||
if (el.id === element.id) { | ||
// update props | ||
el.props = options.props; | ||
} | ||
return el; | ||
}); | ||
// create new element with options and replaces the old | ||
if (index !== -1) { | ||
elements[index] = Object.assign({}, elements[index], options); | ||
elements = updatedElements; | ||
// call update to set attributes and positions based on the new options | ||
this.update(); | ||
} | ||
// call update to set attributes and positions based on the new options | ||
this.update(); | ||
}; | ||
@@ -397,2 +397,3 @@ | ||
_removeParallaxStyles(); | ||
window.ParallaxController = null; | ||
}; | ||
@@ -399,0 +400,0 @@ } |
const ROOT = './example/'; | ||
const createBabelConfig = require('./babelrc'); | ||
const merge = require('webpack-merge'); | ||
@@ -31,3 +30,2 @@ const nodeExternals = require('webpack-node-externals'); | ||
loader: 'babel-loader', | ||
query: createBabelConfig(), | ||
}, | ||
@@ -83,3 +81,2 @@ { | ||
loader: 'babel-loader', | ||
query: createBabelConfig({ server: true }), | ||
}, | ||
@@ -86,0 +83,0 @@ { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
88250
44
1823