Skip to content

Commit 4f50cca

Browse files
committed
Golf bytes to offset change
1 parent 001bbce commit 4f50cca

File tree

5 files changed

+19
-30
lines changed

5 files changed

+19
-30
lines changed

compat/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function isMemo(element) {
7979
return (
8080
!!element &&
8181
typeof element.displayName == 'string' &&
82-
element.displayName.startsWith('Memo(')
82+
element.displayName.indexOf('Memo(') == 0
8383
);
8484
}
8585

compat/src/memo.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,21 @@ import { shallowDiffers } from './util';
1111
export function memo(c, comparer) {
1212
function shouldUpdate(nextProps) {
1313
let ref = this.props.ref;
14-
let updateRef = ref == nextProps.ref;
15-
if (!updateRef && ref) {
16-
ref.call ? ref(null) : (ref.current = null);
14+
if (ref != nextProps.ref && ref) {
15+
typeof ref == 'function' ? ref(null) : (ref.current = null);
1716
}
1817

19-
if (!comparer) {
20-
return shallowDiffers(this.props, nextProps);
21-
}
22-
23-
return !comparer(this.props, nextProps) || !updateRef;
18+
return comparer
19+
? !comparer(this.props, nextProps) || ref != nextProps.ref
20+
: shallowDiffers(this.props, nextProps);
2421
}
2522

2623
function Memoed(props) {
2724
this.shouldComponentUpdate = shouldUpdate;
2825
return createElement(c, props);
2926
}
3027
Memoed.displayName = 'Memo(' + (c.displayName || c.name) + ')';
31-
Memoed.prototype.isReactComponent = true;
32-
Memoed._forwarded = true;
28+
Memoed._forwarded = Memoed.prototype.isReactComponent = true;
3329
Memoed.type = c;
3430
return Memoed;
3531
}

compat/src/render.js

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const onChangeInputType = type =>
4545
).test(type);
4646

4747
// Some libraries like `react-virtualized` explicitly check for this.
48-
Component.prototype.isReactComponent = {};
48+
Component.prototype.isReactComponent = true;
4949

5050
// `UNSAFE_*` lifecycle hooks
5151
// Preact only ever invokes the unprefixed methods.
@@ -105,24 +105,17 @@ let oldEventHook = options.event;
105105
options.event = e => {
106106
if (oldEventHook) e = oldEventHook(e);
107107

108-
e.persist = empty;
109-
e.isPropagationStopped = isPropagationStopped;
110-
e.isDefaultPrevented = isDefaultPrevented;
108+
e.persist = () => {};
109+
e.isPropagationStopped = function isPropagationStopped() {
110+
return this.cancelBubble;
111+
};
112+
e.isDefaultPrevented = function isDefaultPrevented() {
113+
return this.defaultPrevented;
114+
};
111115
return (e.nativeEvent = e);
112116
};
113117

114-
function empty() {}
115-
116-
function isPropagationStopped() {
117-
return this.cancelBubble;
118-
}
119-
120-
function isDefaultPrevented() {
121-
return this.defaultPrevented;
122-
}
123-
124118
const classNameDescriptorNonEnumberable = {
125-
enumerable: false,
126119
configurable: true,
127120
get() {
128121
return this.class;
@@ -132,9 +125,9 @@ const classNameDescriptorNonEnumberable = {
132125
function handleDomVNode(vnode) {
133126
let props = vnode.props,
134127
type = vnode.type,
135-
normalizedProps = {};
128+
normalizedProps = {},
129+
isNonDashedType = type.indexOf('-') == -1;
136130

137-
let isNonDashedType = type.indexOf('-') === -1;
138131
for (let i in props) {
139132
let value = props[i];
140133

compat/test/browser/PureComponent.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,6 @@ describe('PureComponent', () => {
151151

152152
it('should have "isPureReactComponent" property', () => {
153153
let Pure = new React.PureComponent();
154-
expect(Pure.isReactComponent).to.deep.equal({});
154+
expect(Pure.isReactComponent).to.deep.equal(true);
155155
});
156156
});

compat/test/browser/component.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('components', () => {
2020

2121
it('should have "isReactComponent" property', () => {
2222
let Comp = new React.Component();
23-
expect(Comp.isReactComponent).to.deep.equal({});
23+
expect(Comp.isReactComponent).to.deep.equal(true);
2424
});
2525

2626
it('should be sane', () => {

0 commit comments

Comments
 (0)