create-react-apps supports absolute imports via .env
.env
NODE_PATH=src
this will make webpack look for absolute imports (imports without .. or /) in the src directory of our project, meaning we can do something like this
| /** | |
| * Abstract example, a real one will be better | |
| **/ | |
| class MyFog extends Fog { | |
| constructor( fogEnvMap ) { | |
| super() | |
| // initialize whatever you need | |
| // keep some of the shaderChunk shaders and override others |
| class Clock { | |
| constructor( autoStart = true ) { | |
| this.autoStart = autoStart; | |
| this.startTime = 0; | |
| this.oldTime = 0; | |
| this.elapsedTime = 0; |
| const hash = require('object-hash') | |
| const sum = require('hash-sum') | |
| const a = hash({ color: "red" }) | |
| const b = hash({ color: "blue" }) | |
| console.assert(a !== b) | |
| const c = hash({ color: "red", opacity: 1 }, { unorderedObjects: true }) | |
| const d = hash({ opacity: 1, color: "red" }, { unorderedObjects: true }) |
| function createGeometry() { | |
| const r = 2 | |
| const geometry = new THREE.BoxGeometry(2, 2, 2, 32, 32, 32) | |
| const positionAttribute = geometry.attributes.position | |
| for (let i = 0; i < positionAttribute.count; i++) { | |
| const x = positionAttribute.getX(i) | |
| const y = positionAttribute.getY(i) | |
| const z = positionAttribute.getZ(i) |
| // world position | |
| vPositionW = vec3( vec4( position, 1.0 ) * modelMatrix); | |
| // world normal | |
| vNormalW = normalize( vec3( vec4( normal, 0.0 ) * modelMatrix ) ); | |
| // world camera direction | |
| vec3 viewDirectionW = normalize(cameraPosition - vPositionW); | |
| // fresnel, calc with dot mult between view and normal |
| // https://en.m.wikipedia.org/wiki/Rodrigues%27_rotation_formula | |
| vec3 erot(vec3 p, vec3 ax, float ro) { | |
| return mix(dot(p,ax)*ax,p,cos(ro))+sin(ro)*cross(ax,p); | |
| } |
| float mod289(float x){return x - floor(x * (1.0 / 289.0)) * 289.0;} | |
| vec4 mod289(vec4 x){return x - floor(x * (1.0 / 289.0)) * 289.0;} | |
| vec4 perm(vec4 x){return mod289(((x * 34.0) + 1.0) * x);} | |
| float noise(vec3 p){ | |
| vec3 a = floor(p); | |
| vec3 d = p - a; | |
| d = d * d * (3.0 - 2.0 * d); | |
| vec4 b = a.xxyy + vec4(0.0, 1.0, 0.0, 1.0); |
| import yup from 'yup' | |
| import yupErroToReduxFormError from './yupErroToReduxFormError' | |
| // yup schema | |
| const schema = yup.object().shape(...) | |
| // this would be our sync Redux Form validation function | |
| // yup can also validate asynchronously with the yup.validate method | |
| export default (values) => { |
| const images = ['http://picsum.photos/300/300?r&a=1', 'http://picsum.photos/300/300?r&a=2', 'http://picsum.photos/300/300?r&a=3'] | |
| const imageLoadPromise = (src) => new Promise((resolve, reject) => { | |
| const img = new Image() | |
| img.onload = resolve | |
| img.src = src | |
| }) | |
| Promise.all(images.map(imageLoadPromise)) |