Skip to content

Commit

Permalink
refactor: remove cx to reduce bundle size
Browse files Browse the repository at this point in the history
The import was causing emotion to be bundled in with the core library.
  • Loading branch information
ifiokjr committed Jun 16, 2019
1 parent 6ecb934 commit 9219548
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
4 changes: 2 additions & 2 deletions @remirror/core/src/extension-manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cx, Interpolation } from 'emotion';
import { Interpolation } from 'emotion';
import { InputRule, inputRules } from 'prosemirror-inputrules';
import { keymap } from 'prosemirror-keymap';
import { Schema } from 'prosemirror-model';
Expand Down Expand Up @@ -283,7 +283,7 @@ export class ExtensionManager implements ExtensionManagerInitParams {
combinedAttributes = {
...combinedAttributes,
...attrs,
class: cx(combinedAttributes.class, attrs.class),
class: (combinedAttributes.class || '') + bool(attrs.class) ? attrs.class : '',
};
});

Expand Down
49 changes: 34 additions & 15 deletions @remirror/react-utils/src/__tests__/helpers.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,40 @@ test('getElementProps', () => {
expect(getElementProps(Element)).toEqual(expected);
});

test('updateChildWithKey', () => {
expect.assertions(2);
const original = <div key='test' />;
const expected = <div key='test' id='updated' />;
const element = <div>{original}</div>;
const fn = (child: JSX.Element) => {
expect(child).toEqual(original);
return expected;
};

expect(updateChildWithKey(element, 'test', fn)[0]).toMatchInlineSnapshot(`
<div
id="updated"
/>
`);
describe('updateChildWithKey', () => {
it('handles simple use cases', () => {
expect.assertions(2);
const original = <div key='test' />;
const expected = <div key='test' id='updated' />;
const element = <div>{original}</div>;
const fn = (child: JSX.Element) => {
expect(child).toEqual(original);
return expected;
};

expect(updateChildWithKey(element, 'test', fn)[0]).toMatchInlineSnapshot(`
<div
id="updated"
/>
`);
});

it('handles nested use cases', () => {
expect.assertions(2);
const original = <div key='test' />;
const expected = <div key='test' id='updated' />;
const element = <div>{original}</div>;
const fn = (child: JSX.Element) => {
expect(child).toEqual(original);
return expected;
};

expect(updateChildWithKey(element, 'test', fn)[0]).toMatchInlineSnapshot(`
<div
id="updated"
/>
`);
});
});

test('isReactDOMElement', () => {
Expand Down

0 comments on commit 9219548

Please sign in to comment.