Skip to content

Instantly share code, notes, and snippets.

// ----- Given this shader:
vec4 some_noise_fn() {
return vec4(1.0, 2.0, 3.0, 4.0);
}
void main() {
return some_noise_fn();
}
# ----- Given this shader
vec4 some_noise_fn() {
return vec4(1.0, 2.0, 3.0, 4.0);
}
void main() {
return some_noise_fn();
}
export class MyUserForm extends Component {
constructor() {
this.state = { myFormData: {} };
}
render() {
const { myFormData } = this.state;
return (
<MagicForm onChange={data => this.setState({ myFormData: data })}>
@AndrewRayCode
AndrewRayCode / async.willmount.test.js
Created September 4, 2018 01:43
Jest / sinon async componentWillMount test utility function
import { spy } from 'sinon';
import { shallow } from 'enzyme';
// Utility method to asynchronously wait for component's willMount function to
// complete. Requires the componentWillMount method *returns* its async promise
// to wait for
export const willMount = async unmountedComponent => {
// Spy on the willmount method
const lifecycleMethod = spy(unmountedComponent.type.prototype, 'componentWillMount');
const wrapper = shallow(unmountedComponent);
query UserWithAvatarWithoutFriend {
user(id: '1') {
name
avatarImage
}
}
query UserWithoutAvatar {
user(id: '1') {
name
const { baseUrl } = config;
getEndpoints(baseUrl).then(endpoints => {
const data = new Array(endpoints.length);
// Update the array as endpoints come in
endpoints.map((endpoint, index) => {
getEndpointData(endpoint, baseUrl).then(response => {
data[index] = {endpoint, response};
this.setState({ data });
});
class A extends Component {
componentDidMount() {
const { baseUrl } = config;
const data = [];
Promise.all(getEndpoints(baseUrl).then(endpoints => {
return Promise.all(endpoints.map(endpoint => {
return getEndpointData(endpoint, baseUrl).then(response => {
return {endpoint, response};
});
}));
// generic ui component
class Panel {
render() {
return <div>
<b>{this.props.title}</b>
<p>{this.props.body}</p>
</div>;
}
}
const newStatus = { ...this.state.status }; // Copy the object
newStatus['Downloading the song'][1] = 'Info';
this.setState({status : newStatus });
const { status } = this.state.status;
const key = 'Downloading the song';
const downloading = status[key];
const newStatus = {
...status,
key: [
downloading[0],
'Info',
...downloading.slice(2)
]