Permalink
Browse files

Initial commit

  • Loading branch information...
Michael Ridgway
Michael Ridgway committed May 27, 2015
0 parents commit 6e0d9a2898b0f96d54d230f0d0dd0c4280b028a1
Showing with 188 additions and 0 deletions.
  1. +1 −0 .coveralls.yml
  2. +14 −0 .eslintrc
  3. +4 −0 .gitignore
  4. +2 −0 .npmignore
  5. +14 −0 .travis.yml
  6. +29 −0 LICENSE.md
  7. +29 −0 README.md
  8. +25 −0 index.js
  9. +36 −0 package.json
  10. +34 −0 tests/unit/index.js
@@ -0,0 +1 @@
service_name: travis-ci
@@ -0,0 +1,14 @@
---
parser: "babel-eslint"
env:
node: true
rules:
strict: 0
indent: [2, 4]
quotes: [2, 'single']
no-unused-vars: 0 // see https://github.com/babel/babel-eslint/issues/21
no-underscore-dangle: 0
yoda: 0
no-alert: false
new-cap: false
no-empty-class: 0
@@ -0,0 +1,4 @@
/artifacts/
/build/
node_modules
npm-debug.log
@@ -0,0 +1,2 @@
/artifacts/
/tests/
@@ -0,0 +1,14 @@
sudo: false
language: node_js
matrix:
allow_failures:
- node_js: "0.13"
- node_js: "iojs"
node_js:
- "iojs"
- "0.13"
- "0.12"
- "0.10"
after_success:
- "npm run cover"
- "cat artifacts/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
@@ -0,0 +1,29 @@
Software License Agreement (BSD License)
========================================
Copyright (c) 2015, Yahoo! Inc. All rights reserved.
----------------------------------------------------
Redistribution and use of this software in source and binary forms, with or
without modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Yahoo! Inc. nor the names of YUI's contributors may be
used to endorse or promote products derived from this software without
specific prior written permission of Yahoo! Inc.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,29 @@
# hoist-non-react-statics
[![NPM version](https://badge.fury.io/js/hoist-non-react-statics.svg)](http://badge.fury.io/js/hoist-non-react-statics)
[![Build Status](https://img.shields.io/travis/mridgway/hoist-non-react-statics.svg)](https://travis-ci.org/mridgway/hoist-non-react-statics)
[![Coverage Status](https://img.shields.io/coveralls/mridgway/hoist-non-react-statics.svg)](https://coveralls.io/r/mridgway/hoist-non-react-statics?branch=master)
[![Dependency Status](https://img.shields.io/david/mridgway/hoist-non-react-statics.svg)](https://david-dm.org/mridgway/hoist-non-react-statics)
[![devDependency Status](https://img.shields.io/david/dev/mridgway/hoist-non-react-statics.svg)](https://david-dm.org/mridgway/hoist-non-react-statics#info=devDependencies)
Copies non-react specific statics from a child component to a parent component.
Similar to `Object.assign`, but with React static keywords blacklisted from
being overridden.
```bash
$ npm install --save hoist-non-react-statics
```
## Compatible React Versions
| Compatible React Version | hoist-non-react-statics Version |
|--------------------------|-------------------------------|
| 0.13 | >= 1.0.0 |
## License
This software is free to use under the Yahoo Inc. BSD license.
See the [LICENSE file][] for license text and copyright information.
[LICENSE file]: https://github.com/mridgway/hoist-non-react-statics/blob/master/LICENSE.md
Third-party open source code used are listed in our [package.json file]( https://github.com/mridgway/hoist-non-react-statics/blob/master/package.json).
@@ -0,0 +1,25 @@
/**
* Copyright 2015, Yahoo! Inc.
* Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
*/
'use strict';
var REACT_STATICS = {
childContextTypes: true,
contextTypes: true,
displayName: true,
getDefaultProps: true,
mixins: true,
propTypes: true
};
module.exports = function hoistNonReactStatics(targetComponent, sourceComponent) {
var keys = Object.keys(sourceComponent);
for (var i=0; i<keys.length; ++i) {
if (!REACT_STATICS[keys[i]]) {
targetComponent[keys[i]] = sourceComponent[keys[i]];
}
}
return targetComponent;
};
@@ -0,0 +1,36 @@
{
"name": "hoist-non-react-statics",
"version": "0.0.0",
"description": "Copies non-react specific statics from a child component to a parent component",
"main": "index.js",
"repository": {
"type": "git",
"url": "git://github.com/mridgway/hoist-non-react-statics.git"
},
"scripts": {
"cover": "node node_modules/istanbul/lib/cli.js cover --dir artifacts -- ./node_modules/mocha/bin/_mocha tests/unit/ --recursive --compilers js:babel/register --reporter spec",
"lint": "eslint ./index.js",
"test": "mocha tests/unit/ --recursive --compilers js:babel/register --reporter spec"
},
"author": "Michael Ridgway <mridgway@yahoo-inc.com>",
"licenses": [
{
"type": "BSD",
"url": "https://github.com/mridgway/hoist-non-react-statics/blob/master/LICENSE.md"
}
],
"devDependencies": {
"babel": "^5.0.7",
"babel-eslint": "^3.0.1",
"chai": "^2.0.0",
"coveralls": "^2.11.1",
"eslint": "^0.21.0",
"istanbul": "^0.3.2",
"mocha": "^2.0.1",
"pre-commit": "^1.0.7",
"react": "^0.13.3"
},
"keywords": [
"react"
]
}
@@ -0,0 +1,34 @@
/*globals describe,it,beforeEach */
"use strict";
var expect = require('chai').expect;
var React = require('react');
var hoistNonReactStatics = require('../../index');
describe('hoist-non-react-statics', function () {
it('should hoist non react statics', function () {
var Component = React.createClass({
displayName: 'Foo',
statics: {
foo: 'bar'
},
render: function () {
return null;
}
});
var Wrapper = React.createClass({
displayName: 'Bar',
render: function () {
return <Component />;
}
});
hoistNonReactStatics(Wrapper, Component);
expect(Wrapper.displayName).to.equal('Bar');
expect(Wrapper.foo).to.equal('bar');
});
});

0 comments on commit 6e0d9a2

Please sign in to comment.