Skip to content

Commit

Permalink
[changed] deprecate domUtils as a public API
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Aug 20, 2015
1 parent a6e5a9a commit 653d2ff
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
4 changes: 0 additions & 4 deletions src/Affix.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import React from 'react';
import classNames from 'classnames';
import AffixMixin from './AffixMixin';
import domUtils from './utils/domUtils';

const Affix = React.createClass({
statics: {
domUtils
},

mixins: [AffixMixin],

Expand Down
28 changes: 25 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import deprecationWarning from './utils/deprecationWarning';

export Accordion from './Accordion';
export Affix from './Affix';
export AffixMixin from './AffixMixin';
Expand Down Expand Up @@ -70,16 +72,36 @@ export Fade from './Collapse';

export * as FormControls from './FormControls';

import domUtils from './utils/domUtils';
import childrenValueInputValidation from './utils/childrenValueInputValidation';
import createChainedFunction from './utils/createChainedFunction';
import domUtils from './utils/domUtils';
import ValidComponentChildren from './utils/ValidComponentChildren';
import CustomPropTypes from './utils/CustomPropTypes';

export const utils = {
childrenValueInputValidation,
createChainedFunction,
domUtils,
ValidComponentChildren,
CustomPropTypes
CustomPropTypes,
domUtils: createDeprecationWrapper(domUtils, 'utils/domUtils', 'npm install dom-helpers'),
};

function createDeprecationWrapper(obj, deprecated, instead, link){
let wrapper = {};

if (process.env.NODE_ENV === 'production'){
return obj;
}

Object.keys(obj).forEach(key => {
Object.defineProperty(wrapper, key, {
get(){
deprecationWarning(deprecated, instead, link);
return obj[key];
},
set(x){ obj[key] = x; }
});
});

return wrapper;
}
6 changes: 6 additions & 0 deletions src/utils/domUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ function ownerWindow(componentOrElement) {
return getOwnerWindow(doc);
}

//TODO remove in 0.26
function getComputedStyles(elem) {
return ownerDocument(elem).defaultView.getComputedStyle(elem, null);
}

/**
* Get an element's size
*
Expand All @@ -45,6 +50,7 @@ function getSize(elem) {
export default {
canUseDom,
css,
getComputedStyles,
contains,
ownerWindow,
ownerDocument,
Expand Down
3 changes: 3 additions & 0 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import deprecationWarning from './deprecationWarning';

export childrenValueInputValidation from './childrenValueInputValidation';
export createChainedFunction from './createChainedFunction';

deprecationWarning('utils/domUtils', 'npm install dom-helpers');
export domUtils from './domUtils';

export ValidComponentChildren from './ValidComponentChildren';

deprecationWarning('utils/CustomPropTypes', 'npm install react-prop-types',
Expand Down
1 change: 1 addition & 0 deletions webpack/docs.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ if (options.debug) {
}

export default _.extend({}, baseConfig, {

entry: {
bundle: options.debug ? devEntryBundle : entryFile
},
Expand Down

0 comments on commit 653d2ff

Please sign in to comment.