🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@fluentui/react-component-ref

Package Overview
Dependencies
Maintainers
6
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fluentui/react-component-ref - npm Package Compare versions

Comparing version

to
0.49.0

14

dist/commonjs/RefForward.js

@@ -51,2 +51,3 @@ "use strict";

_this = (0, _possibleConstructorReturn2.default)(this, (_getPrototypeOf2 = (0, _getPrototypeOf3.default)(RefForward)).call.apply(_getPrototypeOf2, [this].concat(args)));
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "currentNode", null);
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleRefOverride", function (node) {

@@ -58,2 +59,3 @@ var _this$props = _this.props,

(0, _handleRef.default)(innerRef, node);
_this.currentNode = node;
});

@@ -64,2 +66,14 @@ return _this;

(0, _createClass2.default)(RefForward, [{
key: "componentDidUpdate",
value: function componentDidUpdate(prevProps) {
if (prevProps.innerRef !== this.props.innerRef) {
(0, _handleRef.default)(this.props.innerRef, this.currentNode);
}
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
delete this.currentNode;
}
}, {
key: "render",

@@ -66,0 +80,0 @@ value: function render() {

3

dist/dts/src/RefForward.d.ts

@@ -13,4 +13,7 @@ import * as PropTypes from 'prop-types';

};
currentNode: Node | null;
handleRefOverride: (node: HTMLElement) => void;
componentDidUpdate(prevProps: RefProps): void;
componentWillUnmount(): void;
render(): React.ReactElement<any, string | ((props: any) => React.ReactElement<any, string | any | (new (props: any) => React.Component<any, any, any>)> | null) | (new (props: any) => React.Component<any, any, any>)>;
}

@@ -12,2 +12,3 @@ "use strict";

var _this = _super !== null && _super.apply(this, arguments) || this;
_this.currentNode = null;
_this.handleRefOverride = function (node) {

@@ -17,5 +18,14 @@ var _a = _this.props, children = _a.children, innerRef = _a.innerRef;

handleRef_1.default(innerRef, node);
_this.currentNode = node;
};
return _this;
}
RefForward.prototype.componentDidUpdate = function (prevProps) {
if (prevProps.innerRef !== this.props.innerRef) {
handleRef_1.default(this.props.innerRef, this.currentNode);
}
};
RefForward.prototype.componentWillUnmount = function () {
delete this.currentNode;
};
RefForward.prototype.render = function () {

@@ -22,0 +32,0 @@ var children = this.props.children;

@@ -16,3 +16,27 @@ "use strict";

});
it('passes an updated node', function () {
var innerRef = jest.fn();
var forwardedRef = jest.fn();
var updatedForwardedRef = jest.fn();
var wrapper = enzyme_1.mount(React.createElement(react_component_ref_1.RefForward, { innerRef: innerRef }, (React.createElement(fixtures_1.ForwardedRef, { ref: forwardedRef, key: "first" }))));
expect(innerRef).toHaveBeenCalledWith(expect.objectContaining({ tagName: 'BUTTON' }));
expect(forwardedRef).toHaveBeenCalledWith(expect.objectContaining({ tagName: 'BUTTON' }));
jest.resetAllMocks();
wrapper.setProps({ children: React.createElement(fixtures_1.ForwardedRef, { ref: updatedForwardedRef, key: "second" }) });
expect(innerRef).toHaveBeenCalledWith(expect.objectContaining({ tagName: 'BUTTON' }));
expect(updatedForwardedRef).toHaveBeenCalledWith(expect.objectContaining({ tagName: 'BUTTON' }));
expect(forwardedRef).not.toHaveBeenCalled();
});
it('handles updates of props', function () {
var initialRef = jest.fn();
var updatedRef = jest.fn();
var wrapper = enzyme_1.mount(React.createElement(react_component_ref_1.RefForward, { innerRef: initialRef }, (React.createElement(fixtures_1.ForwardedRef, null))));
expect(initialRef).toHaveBeenCalled();
expect(updatedRef).not.toHaveBeenCalled();
jest.resetAllMocks();
wrapper.setProps({ innerRef: updatedRef });
expect(initialRef).not.toHaveBeenCalled();
expect(updatedRef).toHaveBeenCalled();
});
});
});

@@ -13,4 +13,7 @@ import * as PropTypes from 'prop-types';

};
currentNode: Node | null;
handleRefOverride: (node: HTMLElement) => void;
componentDidUpdate(prevProps: RefProps): void;
componentWillUnmount(): void;
render(): React.ReactElement<any, string | ((props: any) => React.ReactElement<any, string | any | (new (props: any) => React.Component<any, any, any>)> | null) | (new (props: any) => React.Component<any, any, any>)>;
}

@@ -31,2 +31,4 @@ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";

_defineProperty(_assertThisInitialized(_this), "currentNode", null);
_defineProperty(_assertThisInitialized(_this), "handleRefOverride", function (node) {

@@ -38,2 +40,3 @@ var _this$props = _this.props,

handleRef(innerRef, node);
_this.currentNode = node;
});

@@ -45,2 +48,14 @@

_createClass(RefForward, [{
key: "componentDidUpdate",
value: function componentDidUpdate(prevProps) {
if (prevProps.innerRef !== this.props.innerRef) {
handleRef(this.props.innerRef, this.currentNode);
}
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
delete this.currentNode;
}
}, {
key: "render",

@@ -47,0 +62,0 @@ value: function render() {

15

package.json
{
"name": "@fluentui/react-component-ref",
"description": "A set of components and utils to deal with React refs.",
"version": "0.48.0",
"version": "0.49.0",
"author": "Oleksandr Fediashov <olfedias@microsoft.com>",

@@ -14,5 +14,8 @@ "bugs": "https://github.com/microsoft/fluentui/issues",

"@types/react": "16.8.25",
"@types/react-dom": "16.8.4",
"@types/react-is": "^16.7.1",
"@uifabric/build": "^7.0.0",
"lerna-alias": "^3.0.3-0"
"lerna-alias": "^3.0.3-0",
"react": "16.8.6",
"react-dom": "16.8.6"
},

@@ -38,6 +41,4 @@ "files": [

"clean": "gulp bundle:package:clean",
"lint": "yarn lint:eslint && yarn lint:old",
"lint:eslint": "eslint --ext .js,.ts,.tsx .",
"lint:fix": "yarn lint:eslint --fix && yarn lint:old --fix",
"lint:old": "tslint -t stylish -p .",
"lint": "eslint --ext .js,.ts,.tsx .",
"lint:fix": "yarn lint --fix",
"test": "gulp test",

@@ -48,3 +49,3 @@ "test:watch": "gulp test:watch"

"types": "dist/es/index.d.ts",
"gitHead": "0b9847bc9bfdc1c4a0cb35ce0cfcfdc32880500b"
"gitHead": "288ce25b226dfc850712e9b37b8212a226dc14ce"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet