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
| class Title extends React.PureComponent { | |
| domNode = document.createElement('div'); | |
| // ^ it's not added to the document | |
| componentDidMount() { | |
| this.componentDidUpdate(); | |
| } | |
| componentDidUpdate() { | |
| document.title = this.domNode.textContent || ':('; |
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
Show hidden characters
| ... | |
| "plugins": [ | |
| "rewiremock/babel", // babel plugin is required to use "Jest-style" mocking | |
| ] | |
| ... |
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 { remock, createElement } from 'react-remock'; | |
| import { action } from '@storybook/addon-actions'; | |
| remock( | |
| 'button', // for all "buttons" | |
| (type, props, children) => ( | |
| createElement(type, { | |
| ...props, | |
| // override onclick handler | |
| onClick: e => { action(e); props.onClick && props.onClick(e); } |
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
| { | |
| // ... | |
| resolve: { | |
| alias: { | |
| // just replace any "API" you may use, by a "storybook-friendly" one | |
| '/src/api': '/storybook/api', | |
| 'react-redux': ? // probably? mock it out! | |
| } | |
| } |
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
| const state = faste() | |
| .withPhases(['red', 'yellow', 'green']) | |
| .withMessages(['tick','next']) | |
| .on('tick',['green'], ({transit}) => transit('yellow')) | |
| .on('tick',['yellow'], ({transit}) => transit('red')) | |
| .on('tick',['red'], ({transit}) => transit('green')) | |
| // just rethrow next as tick | |
| .on('next',[], ({trigger}) => trigger('tick')) | |
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
| // this package empowers babel-register | |
| const addHook = require('pirates').addHook; | |
| function matcher(filename) { | |
| // do not apply to mocks | |
| return fileName.indexOf('src/mocks') < 0; | |
| } | |
| const PREPEND_TEXT = ` | |
| const window = require('src/mocks/window.js'); |
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 window from 'current-window'; | |
| window.alert('Not alert you are looking for'); |
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 rewiremock from 'rewiremock'; | |
| // somewhere in "setup" | |
| rewiremock('reselect').callThrough(); // mock `reselect` but use original file | |
| // "mocking cycle" | |
| rewiremock.enable(); // rewiremock will wipe all required on `enable` | |
| const App = require('App'); | |
| rewiremock.disable();// and clean on disable |
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
| const wipe = require('wipe-node-cache') or require('wipe-webpack-cache'); | |
| const resolver = (stubs, fileName, module) { | |
| // any logic about should one with some file, or not | |
| return !!stubs[fileName]; | |
| }; | |
| // wipe reselect, and everything depends on it, and everything up to the top | |
| wipe({ | |
| 'reselect/lib/index.js': true, |
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
| // we will "cache" hello using the current language | |
| // of course it will never change :P | |
| let helloMessage = ''; | |
| export const sayHello = (inLng) => { | |
| if (!helloMessage) { | |
| helloMessage = require('hello-message-generator')(inLng); | |
| } | |
| return helloMessage | |
| } |