https://github.com/Shopify/polaris-react/blob/master/src/components/EventListener/EventListener.tsx but it saves events that are being set in context and merges the callback if appropriate. The goal is to improve performance and prevent cases where one page would have say 3 event listeners for the same event.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
Prefetch HTML page the user might navigate to | |
https://developer.mozilla.org/en-US/docs/Web/HTTP/Link_prefetching_FAQ | |
--> | |
<link rel="prefetch" href="/signup.html"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function showMessage(message: string) { | |
console.log('message', message); | |
return (...args: any[]) => { | |
const [constructorOrComponent, propertyKey, descriptor] = args; | |
if (typeof constructorOrComponent === 'function') { | |
console.log('Class', constructorOrComponent); | |
return constructorOrComponent; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
import {mount} from 'enzyme'; | |
import {UnstyledLink, Button} from '../components'; | |
import Link from '../Link'; | |
describe('<Link />', () => { | |
const mockProps = { | |
children: 'Click me!', | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
import {mount} from 'enzyme'; | |
import {UnstyledLink, Button} from '../components'; | |
import Link from '../Link'; | |
describe('<Link />', () => { | |
const mockProps = { | |
children: 'Click me!', | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
import {isExternal} from './utilities'; | |
import {UnstyledLink, Button} from './components'; | |
interface Props { | |
children: React.ReactNode; | |
href?: string; | |
onClick?(): void; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {trigger} from '@shopify/enzyme-utilities'; | |
... | |
describe('onChange()', () => { | |
it('triggers when the user types', () => { | |
const onChangeSpy = jest.fn(); | |
const event = {}; | |
const textField = mount( | |
<TextField {...mockProps} onChange={onChangeSpy} />, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('onChange()', () => { | |
it('triggers when the user types', () => { | |
const onChangeSpy = jest.fn(); | |
const event = {}; | |
const textField = mount( | |
<TextField {...mockProps} onChange={onChangeSpy} />, | |
); | |
(textField.find('input').prop('onChange') as any)(event); | |
expect(onChangeSpy).toHaveBeenCalledTimes(1); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
import {mount} from 'enzyme'; | |
import {noop} from '@shopify/javascript-utilities/other'; | |
import TextField from '../TextField'; | |
describe('<TextField />', () => { | |
const mockProps = { | |
onChange: noop, | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
import {mount} from 'enzyme'; | |
import {noop} from '@shopify/javascript-utilities/other'; | |
import TextField from '../TextField'; | |
describe('<TextField />', () => { | |
const mockProps = { | |
onChange: noop, | |
}; |