Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* @providesModule ReactVoice
*/
'use strict';
const {spawnSync} = require('child_process');
const ReactDOMFrameScheduling = require('ReactDOMFrameScheduling');
const ReactFiberReconciler = require('ReactFiberReconciler');
const sideEffect = (method, text) => spawnSync('say', ['-v', method, text]);
const VoiceRenderer = ReactFiberReconciler({
getRootHostContext() {
return {};
},
getChildHostContext() {
return {};
},
getPublicInstance(instance) {
return null;
},
createInstance(type, props) {
return {};
},
appendInitialChild(parentInstance, child) {},
finalizeInitialChildren(host, type, props) {
if (typeof props.children === 'string') {
sideEffect(type, props.children);
}
return false;
},
prepareUpdate(instance, type, oldProps, newProps) {
return {};
},
commitMount(instance, type, newProps) {},
commitUpdate(instance, updatePayload, type, oldProps, newProps) {
if (typeof newProps.children === 'string') {
if (newProps.children !== oldProps.children) {
sideEffect(type, newProps.children);
}
}
},
shouldSetTextContent(type, props) {},
resetTextContent(instance) {},
shouldDeprioritizeSubtree(type, props) {},
createTextInstance(text, rootContainerInstance, hostContext, internalInstanceHandle) {},
commitTextUpdate(textInstance, oldText, newText) {},
appendChild(parentInstance, child) {},
appendChildToContainer(parentInstance, child) {},
insertBefore(parentInstance, child, beforeChild) {},
insertInContainerBefore(container, child, beforeChild) {},
removeChild(parentInstance, child) {},
removeChildFromContainer(container, child) {},
prepareForCommit() {},
resetAfterCommit() {},
scheduleDeferredCallback: ReactDOMFrameScheduling.rIC,
useSyncScheduling: true,
});
let root;
const ReactVoice = {
render(element, callback) {
if (!root) {
const container = {};
root = VoiceRenderer.createContainer(container);
}
VoiceRenderer.updateContainer(element, root, null, callback);
},
};
module.exports = ReactVoice;
const React = require('react');
const ReactVoice = require('ReactVoice');
describe('ReactVoice', () => {
it('should say a text', () => {
ReactVoice.render([
<alex key={1}>Hello</alex>,
<victoria key={2}>React Fiber</victoria>,
<kyoko key={3}>こんにちは HTML5 Conference</kyoko>,
]);
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment