code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
toString() { return `WglShader(fragmentShaderSource: ${this.fragmentShaderSourceGenerator()})`; }
Returns the same shader, but parameterized by the given arguments. Call renderTo on the result to render to a destination texture. @param {!WglArg} uniformArguments @returns {!WglConfiguredShader}
toString
javascript
Strilanc/Quirk
src/webgl/WglShader.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglShader.js
Apache-2.0
constructor(fragmentShaderSource, uniformParameterNames) { let ctx = initializedWglContext(); let precision = ctx.maximumShaderFloatPrecision; let vertexShader = ` precision ${precision} float; precision ${precision} int; attribute vec2 position; v...
@param {!string} fragmentShaderSource @param {!Array.<!string>|!Iterable.<!string>} uniformParameterNames
constructor
javascript
Strilanc/Quirk
src/webgl/WglShader.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglShader.js
Apache-2.0
static compileShader(gl, shaderType, sourceCode) { let shader = gl.createShader(shaderType); gl.shaderSource(shader, sourceCode); gl.compileShader(shader); let info = gl.getShaderInfoLog(shader); if (info !== '') { let ignored = false; for (let term of C...
@param {!WebGLRenderingContext} gl @param {number} shaderType @param {!string} sourceCode @returns {!WebGLShader}
compileShader
javascript
Strilanc/Quirk
src/webgl/WglShader.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglShader.js
Apache-2.0
constructor(width, height, pixelType = WebGLRenderingContext.FLOAT) { if (width === 0 && height === 0) { this.width = 0; this.height = 0; this.pixelType = pixelType; this._hasBeenRenderedTo = true; this._textureAndFrameBufferSlot = new WglMortalValueSl...
@param {!int} width @param {!int} height @param {!int} pixelType FLOAT or UNSIGNED_BYTE
constructor
javascript
Strilanc/Quirk
src/webgl/WglTexture.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglTexture.js
Apache-2.0
static preferredWidthHeightForSizePower(sizePower) { let w = 1 << Math.ceil(sizePower / 2); let h = 1 << Math.floor(sizePower / 2); if (w === 2 && h === 2) { w = 4; h = 1; } return {w, h}; }
@param {!int} sizePower @returns {{w: !int, h: !int}}
preferredWidthHeightForSizePower
javascript
Strilanc/Quirk
src/webgl/WglTexture.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglTexture.js
Apache-2.0
sizePower() { if (this.width === 0) { return -Infinity; } return Math.round(Math.log2(this.width * this.height)); }
Returns the base-2 logarithm of the texture's area. @returns {!int}
sizePower
javascript
Strilanc/Quirk
src/webgl/WglTexture.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglTexture.js
Apache-2.0
invalidateButMoveToNewInstance(details) { let result = new WglTexture(this.width, this.height, this.pixelType); result._textureAndFrameBufferSlot = this._textureAndFrameBufferSlot; let invalidated = () => { throw new DetailedError("WglTexture's value accessed after invalidation.", details) }; ...
For catching use-after-free bugs, despite texture pooling. Moves the underlying WebGLTexture to a new instance, and marks this instance as invalidated. @param {*} details @returns {!WglTexture}
invalidateButMoveToNewInstance
javascript
Strilanc/Quirk
src/webgl/WglTexture.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglTexture.js
Apache-2.0
_textureAndFramebufferInitializer() { const GL = WebGLRenderingContext; let gl = initializedWglContext().gl; let result = { texture: gl.createTexture(), framebuffer: gl.createFramebuffer() }; gl.bindTexture(GL.TEXTURE_2D, result.texture); gl.bind...
@returns {!{texture: !WebGLTexture, framebuffer: !WebGLFramebuffer}} @private
_textureAndFramebufferInitializer
javascript
Strilanc/Quirk
src/webgl/WglTexture.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglTexture.js
Apache-2.0
readPixels(isOnHotPath=true) { const GL = WebGLRenderingContext; if (!this._hasBeenRenderedTo) { throw new Error("Called readPixels on a texture that hasn't been rendered to."); } let outputBuffer; switch (this.pixelType) { case GL.UNSIGNED_BYTE: ...
Performs a blocking read of the pixel color data in this texture. @param {!boolean} isOnHotPath @returns {!Uint8Array|!Float32Array}
readPixels
javascript
Strilanc/Quirk
src/webgl/WglTexture.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglTexture.js
Apache-2.0
static _bucketFor(sizePower, pixelType) { if (!Number.isInteger(sizePower) || sizePower < 0 || sizePower > 50) { throw new DetailedError("Bad sizePower", {sizePower, pixelType}); } let pool = pixelType === WebGLRenderingContext.FLOAT ? FLOAT_POOL : BYTE_POOL; while (pool.len...
@param {!int} sizePower @param {!int} pixelType @returns {!Array.<!WglTexture>} @private
_bucketFor
javascript
Strilanc/Quirk
src/webgl/WglTexturePool.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglTexturePool.js
Apache-2.0
static take(sizePower, pixelType) { if (sizePower === -Infinity) { return new WglTexture(0, 0, pixelType); } let bucket = WglTexturePool._bucketFor(sizePower, pixelType); unreturnedTextureCount++; if (unreturnedTextureCount > 1000) { console.warn(`High bo...
Allocates a texture with the given pixel type with a total area of 1<<sizePower. If there is a matching texture in the pool, it will be taken instead of initializing a new texture. @param {!int} sizePower @param {!int} pixelType @returns {!WglTexture}
take
javascript
Strilanc/Quirk
src/webgl/WglTexturePool.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglTexturePool.js
Apache-2.0
static deposit(texture, detailsShownWhenUsedAfterDone='[no dealloc details]') { if (!(texture instanceof WglTexture)) { throw new DetailedError("Not a texture", {texture, detailsShownWhenUsedAfterDone}); } if (texture.width === 0) { return; } let bucket =...
Puts the texture back into the texture pool. @param {!WglTexture} texture @param {*=} detailsShownWhenUsedAfterDone @returns {void}
deposit
javascript
Strilanc/Quirk
src/webgl/WglTexturePool.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglTexturePool.js
Apache-2.0
static takeSame(texture) { return WglTexturePool.take(texture.sizePower(), texture.pixelType); }
Allocates a texture with the same size and type as the given texture. @param {!WglTexture} texture @returns {!WglTexture}
takeSame
javascript
Strilanc/Quirk
src/webgl/WglTexturePool.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglTexturePool.js
Apache-2.0
static getUnReturnedTextureCount() { return unreturnedTextureCount; }
Determines how many textures have been taken from the pool without yet being given back. @returns {!int}
getUnReturnedTextureCount
javascript
Strilanc/Quirk
src/webgl/WglTexturePool.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglTexturePool.js
Apache-2.0
static takeRawFloatTex(sizePower) { return WglTexturePool.take( sizePower, WebGLRenderingContext.FLOAT); }
Allocates a FLOAT RGBA texture with an area of 1<<sizePower. Some GPUs don't support rendering to and/or reading pixels from float textures. If you want the floats to be encoded into bytes if necessary, use takeVecFloatTex instead. @param {!int} sizePower @returns {!WglTexture}
takeRawFloatTex
javascript
Strilanc/Quirk
src/webgl/WglTexturePool.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglTexturePool.js
Apache-2.0
static takeRawByteTex(sizePower) { return WglTexturePool.take( sizePower, WebGLRenderingContext.UNSIGNED_BYTE); }
Allocates an UNSIGNED_BYTE RGBA texture with an area of 1<<sizePower. @param {!int} sizePower @returns {!WglTexture}
takeRawByteTex
javascript
Strilanc/Quirk
src/webgl/WglTexturePool.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglTexturePool.js
Apache-2.0
static takeBoolTex(sizePower) { return WglTexturePool.take( sizePower, WebGLRenderingContext.UNSIGNED_BYTE); }
Allocates a texture for storing an encoded array of 1<<sizePower booleans (encoded into bytes). @param {!int} sizePower @returns {!WglTexture}
takeBoolTex
javascript
Strilanc/Quirk
src/webgl/WglTexturePool.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglTexturePool.js
Apache-2.0
static takeVecFloatTex(sizePower) { return WglTexturePool.take( sizePower + currentShaderCoder().float.powerSizeOverhead, currentShaderCoder().float.pixelType); }
Allocates a texture for storing an encoded array of 1<<sizePower floats (possibly encoded into bytes). @param {!int} sizePower @returns {!WglTexture}
takeVecFloatTex
javascript
Strilanc/Quirk
src/webgl/WglTexturePool.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglTexturePool.js
Apache-2.0
static takeVec2Tex(sizePower) { return WglTexturePool.take( sizePower + currentShaderCoder().vec2.powerSizeOverhead, currentShaderCoder().vec2.pixelType); }
Allocates a texture for storing an encoded array of 1<<sizePower float-pairs (possibly encoded into bytes). @param {!int} sizePower @returns {!WglTexture}
takeVec2Tex
javascript
Strilanc/Quirk
src/webgl/WglTexturePool.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglTexturePool.js
Apache-2.0
static takeVec4Tex(sizePower) { return WglTexturePool.take( sizePower + currentShaderCoder().vec4.powerSizeOverhead, currentShaderCoder().vec4.pixelType); }
Allocates a texture for storing an encoded array of 1<<sizePower float-quadruplets (possibly encoded into bytes). @param {!int} sizePower @returns {!WglTexture}
takeVec4Tex
javascript
Strilanc/Quirk
src/webgl/WglTexturePool.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglTexturePool.js
Apache-2.0
dontDeallocCurrentTexture() { this._dontDeallocFlag = true; return this.currentTexture; }
Tells the texture trader that when it trades away the current texture it shouldn't dealloc it. @returns {!WglTexture} The current texture. You're responsible for it now, caller.
dontDeallocCurrentTexture
javascript
Strilanc/Quirk
src/webgl/WglTextureTrader.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglTextureTrader.js
Apache-2.0
shadeAndTrade(shaderFunc, newTexture=undefined) { let src = this.currentTexture; let deallocSrc = !this._dontDeallocFlag; let dst = newTexture || WglTexturePool.takeSame(src); let configuredShader = shaderFunc instanceof WglConfiguredShader ? shaderFunc : shaderFunc(src); config...
Applies the given shader function to the trader's old texture, renders it onto a new texture, deallocs the old texture, and finally holds on to the new texture. @param {!WglConfiguredShader|!function(!WglTexture) : !WglConfiguredShader} shaderFunc @param {undefined|!WglTexture} newTexture The texture to take and shade...
shadeAndTrade
javascript
Strilanc/Quirk
src/webgl/WglTextureTrader.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglTextureTrader.js
Apache-2.0
shadeHalveAndTrade(reducingShaderFunc) { this.shadeAndTrade( reducingShaderFunc, WglTexturePool.take(Math.max(0, this.currentTexture.sizePower() - 1), this.currentTexture.pixelType)) }
Renders to a texture that's a half the size of the current texture, then uses the rendered texture as the new current texture. @param {!function(!WglTexture) : !WglConfiguredShader} reducingShaderFunc
shadeHalveAndTrade
javascript
Strilanc/Quirk
src/webgl/WglTextureTrader.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglTextureTrader.js
Apache-2.0
shadeQuarterAndTrade(reducingShaderFunc) { this.shadeAndTrade( reducingShaderFunc, WglTexturePool.take(Math.max(0, this.currentTexture.sizePower() - 2), this.currentTexture.pixelType)) }
Renders to a texture that's a quarter of the size of the current texture, then uses the rendered texture as the new current texture. @param {!function(!WglTexture) : !WglConfiguredShader} reducingShaderFunc
shadeQuarterAndTrade
javascript
Strilanc/Quirk
src/webgl/WglTextureTrader.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglTextureTrader.js
Apache-2.0
function checkGetErrorResult(gl, previousOperationDescription, isOnHotPath = false) { if (isOnHotPath && !Config.CHECK_WEB_GL_ERRORS_EVEN_ON_HOT_PATHS) { return; } let code = gl.getError(); const GL = WebGLRenderingContext; if (code === GL.NO_ERROR) { return; } const msgs = ...
Checks if the given code, returned by gl.getError, is an error or not. Throws an error with a descriptive message if the code represents an error. @param {!WebGLRenderingContext} gl @param {!string} previousOperationDescription @param {!boolean} isOnHotPath
checkGetErrorResult
javascript
Strilanc/Quirk
src/webgl/WglUtil.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglUtil.js
Apache-2.0
function checkFrameBufferStatusResult(gl, isOnHotPath = false) { if (isOnHotPath && !Config.CHECK_WEB_GL_ERRORS_EVEN_ON_HOT_PATHS) { return; } const GL = WebGLRenderingContext; let code = gl.checkFramebufferStatus(GL.FRAMEBUFFER); if (code === GL.FRAMEBUFFER_COMPLETE) { return; ...
Checks if the given code, returned by gl.checkFramebufferStatus, is an error or not. Throws an error with a descriptive message if the code represents an error. @param {!WebGLRenderingContext} gl @param {!boolean} isOnHotPath
checkFrameBufferStatusResult
javascript
Strilanc/Quirk
src/webgl/WglUtil.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglUtil.js
Apache-2.0
function assertThatCircuitShaderActsLikeMatrix(shaderFunc, matrix, repeats=5) { assertThatCircuitUpdateActsLikeMatrix( ctx => ctx.applyOperation(shaderFunc), matrix, repeats); }
@param {function(!CircuitEvalContext) : !WglConfiguredShader} shaderFunc @param {!Matrix} matrix @param {!int=} repeats
assertThatCircuitShaderActsLikeMatrix
javascript
Strilanc/Quirk
test/CircuitOperationTestUtil.js
https://github.com/Strilanc/Quirk/blob/master/test/CircuitOperationTestUtil.js
Apache-2.0
function assertThatGateActsLikePermutation( gate, permutationFunc, inputSpans=[], ignoreTargetEndsUpDisabled=false) { let inputGates = []; for (let [key, inputGate] of [['Input Range A', Gates.InputGates.InputAFamily], ['Input Range B', Gates.Inp...
@param {!Gate} gate @param {!function(target : !int,inputA:!int) : !int | !function(target : !int, inputA : !int, inputB : !int) : !int | !function(target : !int, inputA : !int, inputB : !int, inputR : !int) : !int} permutationFunc @param {!Array.<!int>=} inputSpans @param {!boolean} ignoreTargetEndsUpD...
assertThatGateActsLikePermutation
javascript
Strilanc/Quirk
test/CircuitOperationTestUtil.js
https://github.com/Strilanc/Quirk/blob/master/test/CircuitOperationTestUtil.js
Apache-2.0
fullPermutation = val => { let dst = (val & dstMask) >> dstWire; let inps = seq(inpMasks).zip(inpWires, (m, w) => (val & m) >> w).toArray(); let out = permutationFunc(dst, ...inps); return (val & ~dstMask) | out; }
@param {!Gate} gate @param {!function(target : !int,inputA:!int) : !int | !function(target : !int, inputA : !int, inputB : !int) : !int | !function(target : !int, inputA : !int, inputB : !int, inputR : !int) : !int} permutationFunc @param {!Array.<!int>=} inputSpans @param {!boolean} ignoreTargetEndsUpD...
fullPermutation
javascript
Strilanc/Quirk
test/CircuitOperationTestUtil.js
https://github.com/Strilanc/Quirk/blob/master/test/CircuitOperationTestUtil.js
Apache-2.0
fullPermutation = val => { let dst = (val & dstMask) >> dstWire; let inps = seq(inpMasks).zip(inpWires, (m, w) => (val & m) >> w).toArray(); let out = permutationFunc(dst, ...inps); return (val & ~dstMask) | out; }
@param {!Gate} gate @param {!function(target : !int,inputA:!int) : !int | !function(target : !int, inputA : !int, inputB : !int) : !int | !function(target : !int, inputA : !int, inputB : !int, inputR : !int) : !int} permutationFunc @param {!Array.<!int>=} inputSpans @param {!boolean} ignoreTargetEndsUpD...
fullPermutation
javascript
Strilanc/Quirk
test/CircuitOperationTestUtil.js
https://github.com/Strilanc/Quirk/blob/master/test/CircuitOperationTestUtil.js
Apache-2.0
function assertThatGateActsLikePhaser(gate, phaserFunc, forcedTime=undefined) { let wireCount = gate.height; let col = new Array(wireCount).fill(undefined); col[0] = gate; let circuit = new CircuitDefinition(wireCount, [new GateColumn(col)]); let matrix = Matrix.generateDiagonal(1 << wireCount, k =>...
@param {!Gate} gate @param {!function(target : !int) : !number} phaserFunc @param {!number|undefined=} forcedTime
assertThatGateActsLikePhaser
javascript
Strilanc/Quirk
test/CircuitOperationTestUtil.js
https://github.com/Strilanc/Quirk/blob/master/test/CircuitOperationTestUtil.js
Apache-2.0
function assertThatCircuitUpdateActsLikeMatrix(updateAction, matrix, repeats=5, forcedTime=undefined) { for (let i = 0; i < repeats; i++) { assertThatCircuitMutationActsLikeMatrix_single(updateAction, matrix, forcedTime); } }
@param {function(!CircuitEvalContext)} updateAction @param {!Matrix} matrix @param {!int=} repeats @param {!number|undefined=} forcedTime
assertThatCircuitUpdateActsLikeMatrix
javascript
Strilanc/Quirk
test/CircuitOperationTestUtil.js
https://github.com/Strilanc/Quirk/blob/master/test/CircuitOperationTestUtil.js
Apache-2.0
function assertThatCircuitMutationActsLikeMatrix_single(updateAction, matrix, forcedTime=undefined) { let qubitSpan = Math.round(Math.log2(matrix.height())); let extraWires = Math.floor(Math.random()*5); let time = Math.random(); let qubitIndex = Math.floor(Math.random() * extraWires); if (USE_SIMPL...
@param {function(!CircuitEvalContext)} updateAction @param {!Matrix} matrix @param {!number|undefined=} forcedTime
assertThatCircuitMutationActsLikeMatrix_single
javascript
Strilanc/Quirk
test/CircuitOperationTestUtil.js
https://github.com/Strilanc/Quirk/blob/master/test/CircuitOperationTestUtil.js
Apache-2.0
function assertThatCircuitShaderActsLikePermutation(wireCount, shaderMaker, permutation, permuteInfo=undefined) { assertThatCircuitUpdateActsLikePermutation( wireCount, ctx => ctx.applyOperation(shaderMaker(ctx)), permutation, permuteInfo) }
@param {!int} wireCount The number of wires in the circuit. @param {!function(!CircuitEvalContext) : !WglConfiguredShader} shaderMaker Makes the shader to apply. @param {!function(!int) : !int} permutation The expected permutation. @param {*} permuteInfo Debug info included when the assertion fails.
assertThatCircuitShaderActsLikePermutation
javascript
Strilanc/Quirk
test/CircuitOperationTestUtil.js
https://github.com/Strilanc/Quirk/blob/master/test/CircuitOperationTestUtil.js
Apache-2.0
function assertThatCircuitUpdateActsLikePermutation(wireCount, updateAction, permutation, permuteInfo=undefined) { let time = Math.random(); let ampCount = 1 << wireCount; let inVec = Matrix.generate(1, ampCount, r => new Complex(r + Math.random(), Math.random()*1000)); let tex = Shaders.vec2Data(inVec...
@param {!int} wireCount The number of wires in the circuit. @param {!function(!CircuitEvalContext)} updateAction The actual update action. @param {!function(!int) : !int} permutation The expected permutation. @param {*} permuteInfo Debug info included when the assertion fails.
assertThatCircuitUpdateActsLikePermutation
javascript
Strilanc/Quirk
test/CircuitOperationTestUtil.js
https://github.com/Strilanc/Quirk/blob/master/test/CircuitOperationTestUtil.js
Apache-2.0
function isApproximatelyEqualToHelper(subject, other, epsilon) { if (subject === null) { return other === null; } else if (subject === undefined) { return other === undefined; } else if (subject.isApproximatelyEqualTo !== undefined) { return subject.isApproximatelyEqualTo(other, epsi...
@param {*} subject @param {*} other @param {!number} epsilon @returns {!boolean} @private
isApproximatelyEqualToHelper
javascript
Strilanc/Quirk
test/TestUtil.js
https://github.com/Strilanc/Quirk/blob/master/test/TestUtil.js
Apache-2.0
function isApproximatelyEqualToHelperDestructured(subject, other, epsilon) { let keys = []; for (let subjectKey in subject) { if (subject.hasOwnProperty(subjectKey)) { keys.push(subjectKey); } } for (let otherKey in other) { if (other.hasOwnProperty(otherKey) && !subj...
@param {!Object} subject @param {!Object} other @param {!number} epsilon @returns {!boolean} @private
isApproximatelyEqualToHelperDestructured
javascript
Strilanc/Quirk
test/TestUtil.js
https://github.com/Strilanc/Quirk/blob/master/test/TestUtil.js
Apache-2.0
constructor(subject, id=undefined, info=undefined) { sanityCheck(subject); assertionSubjectIndexForNextTest += 1; /** * The "actual" value, to be compared against expected values. * @type {*} */ this.subject = subject; /** * @type {*} ...
@param {*} subject @param {*} id @param {*} info @property {*} subject
constructor
javascript
Strilanc/Quirk
test/TestUtil.js
https://github.com/Strilanc/Quirk/blob/master/test/TestUtil.js
Apache-2.0
function assertThat(subject, extraArgCatcher) { if (extraArgCatcher !== undefined) { fail('Extra assertThat arg'); } return new AssertionSubject(subject, 'assertThat #' + assertionSubjectIndexForNextTest); }
Returns an assertion subject for the given value, which can be fluently extended with conditions like "isEqualTo". @param {*} subject @param {=undefined} extraArgCatcher returns {!AssertionSubject}
assertThat
javascript
Strilanc/Quirk
test/TestUtil.js
https://github.com/Strilanc/Quirk/blob/master/test/TestUtil.js
Apache-2.0
function assertThrows(func, extraArgCatcher) { if (extraArgCatcher !== undefined) { fail('Extra assertThrows arg'); } try { func(); } catch(ex) { return new AssertionSubject(ex, 'assertThrows'); } fail('Expected an exception to be thrown by ' + func); return undefined...
Invokes a function, requiring it to throw an exception. Returns the exception wrapped in an assertion subject. @param {function()} func @param {=undefined} extraArgCatcher returns {!AssertionSubject}
assertThrows
javascript
Strilanc/Quirk
test/TestUtil.js
https://github.com/Strilanc/Quirk/blob/master/test/TestUtil.js
Apache-2.0
test(name, method, later=false) { (later ? this.later_tests : this.tests).push([name, status => { assertionSubjectIndexForNextTest = 1; let result = method(status); if (result === undefined && assertionSubjectIndexForNextTest === 1) { console.warn(`No assertio...
@param {!string} name @param {!function(!{ warn_only: !boolean|!string })} method @param {!boolean=false} later
test
javascript
Strilanc/Quirk
test/TestUtil.js
https://github.com/Strilanc/Quirk/blob/master/test/TestUtil.js
Apache-2.0
testUsingWebGL(name, method, needsFloatSupport=false) { let wrappedMethod = (caseName, status, subNeedFloats) => { if (subNeedFloats && !canTestFloatShaders()) { let msg = `Skipping ${this.name}.${caseName} due to lack of WebGL float texture support.`; console.warn(ms...
@param {!string} name @param {!function(!{ warn_only: !boolean|!string })} method @param {!boolean=false} needsFloatSupport
testUsingWebGL
javascript
Strilanc/Quirk
test/TestUtil.js
https://github.com/Strilanc/Quirk/blob/master/test/TestUtil.js
Apache-2.0
wrappedMethod = (caseName, status, subNeedFloats) => { if (subNeedFloats && !canTestFloatShaders()) { let msg = `Skipping ${this.name}.${caseName} due to lack of WebGL float texture support.`; console.warn(msg); status.log.push(msg); assertThat...
@param {!string} name @param {!function(!{ warn_only: !boolean|!string })} method @param {!boolean=false} needsFloatSupport
wrappedMethod
javascript
Strilanc/Quirk
test/TestUtil.js
https://github.com/Strilanc/Quirk/blob/master/test/TestUtil.js
Apache-2.0
wrappedMethod = (caseName, status, subNeedFloats) => { if (subNeedFloats && !canTestFloatShaders()) { let msg = `Skipping ${this.name}.${caseName} due to lack of WebGL float texture support.`; console.warn(msg); status.log.push(msg); assertThat...
@param {!string} name @param {!function(!{ warn_only: !boolean|!string })} method @param {!boolean=false} needsFloatSupport
wrappedMethod
javascript
Strilanc/Quirk
test/TestUtil.js
https://github.com/Strilanc/Quirk/blob/master/test/TestUtil.js
Apache-2.0
testUsingWebGLFloatTextures(name, method) { this.testUsingWebGL(name, method, true); }
@param {!string} name @param {!function(!{ warn_only: !boolean|!string })} method
testUsingWebGLFloatTextures
javascript
Strilanc/Quirk
test/TestUtil.js
https://github.com/Strilanc/Quirk/blob/master/test/TestUtil.js
Apache-2.0
canvasAppearanceTest(name, width, height, method, expectedSrc, tolerance = 256) { this.test(name, status => { let actualCanvas = /** @type {!HTMLCanvasElement} */ document.createElement("canvas"); actualCanvas.width = width; actualCanvas.height = height; method(ac...
A test that compares the drawing, performed by the test method on the given canvas, to the given expected image or data. @param {!string} name @param {!int} width @param {!int} height @param {!function(!HTMLCanvasElement, !{ warn_only: !boolean|!string })} method @param {!string} expectedSrc Either the location of an a...
canvasAppearanceTest
javascript
Strilanc/Quirk
test/TestUtil.js
https://github.com/Strilanc/Quirk/blob/master/test/TestUtil.js
Apache-2.0
bad = (col, row, diagram, ...extraGates) => assertThat(circuit(diagram, ...extraGates).gateAtLocIsDisabledReason(col, row)).isNotEqualTo(undefined)
@param {!int} col @param {!int} row @param {!string} diagram @param {![!string, !Gate]} extraGates
bad
javascript
Strilanc/Quirk
test/circuit/CircuitDefinition.test.js
https://github.com/Strilanc/Quirk/blob/master/test/circuit/CircuitDefinition.test.js
Apache-2.0
bad = (col, row, diagram, ...extraGates) => assertThat(circuit(diagram, ...extraGates).gateAtLocIsDisabledReason(col, row)).isNotEqualTo(undefined)
@param {!int} col @param {!int} row @param {!string} diagram @param {![!string, !Gate]} extraGates
bad
javascript
Strilanc/Quirk
test/circuit/CircuitDefinition.test.js
https://github.com/Strilanc/Quirk/blob/master/test/circuit/CircuitDefinition.test.js
Apache-2.0
good = (col, row, diagram, ...extraGates) => assertThat(circuit(diagram, ...extraGates).gateAtLocIsDisabledReason(col, row)).isEqualTo(undefined)
@param {!int} col @param {!int} row @param {!string} diagram @param {![!string, !Gate]} extraGates
good
javascript
Strilanc/Quirk
test/circuit/CircuitDefinition.test.js
https://github.com/Strilanc/Quirk/blob/master/test/circuit/CircuitDefinition.test.js
Apache-2.0
good = (col, row, diagram, ...extraGates) => assertThat(circuit(diagram, ...extraGates).gateAtLocIsDisabledReason(col, row)).isEqualTo(undefined)
@param {!int} col @param {!int} row @param {!string} diagram @param {![!string, !Gate]} extraGates
good
javascript
Strilanc/Quirk
test/circuit/CircuitDefinition.test.js
https://github.com/Strilanc/Quirk/blob/master/test/circuit/CircuitDefinition.test.js
Apache-2.0
bad = (col, row, diagram, ...extraGates) => assertThat(circuit( diagram, ...ownExtraGates, ...extraGates).gateAtLocIsDisabledReason(col, row)).isNotEqualTo(undefined)
@param {!int} col @param {!int} row @param {!string} diagram @param {![!string, !Gate]} extraGates
bad
javascript
Strilanc/Quirk
test/circuit/CircuitDefinition.test.js
https://github.com/Strilanc/Quirk/blob/master/test/circuit/CircuitDefinition.test.js
Apache-2.0
bad = (col, row, diagram, ...extraGates) => assertThat(circuit( diagram, ...ownExtraGates, ...extraGates).gateAtLocIsDisabledReason(col, row)).isNotEqualTo(undefined)
@param {!int} col @param {!int} row @param {!string} diagram @param {![!string, !Gate]} extraGates
bad
javascript
Strilanc/Quirk
test/circuit/CircuitDefinition.test.js
https://github.com/Strilanc/Quirk/blob/master/test/circuit/CircuitDefinition.test.js
Apache-2.0
good = (col, row, diagram, ...extraGates) => assertThat(circuit( diagram, ...ownExtraGates, ...extraGates).gateAtLocIsDisabledReason(col, row)).isEqualTo(undefined)
@param {!int} col @param {!int} row @param {!string} diagram @param {![!string, !Gate]} extraGates
good
javascript
Strilanc/Quirk
test/circuit/CircuitDefinition.test.js
https://github.com/Strilanc/Quirk/blob/master/test/circuit/CircuitDefinition.test.js
Apache-2.0
good = (col, row, diagram, ...extraGates) => assertThat(circuit( diagram, ...ownExtraGates, ...extraGates).gateAtLocIsDisabledReason(col, row)).isEqualTo(undefined)
@param {!int} col @param {!int} row @param {!string} diagram @param {![!string, !Gate]} extraGates
good
javascript
Strilanc/Quirk
test/circuit/CircuitDefinition.test.js
https://github.com/Strilanc/Quirk/blob/master/test/circuit/CircuitDefinition.test.js
Apache-2.0
bad = (col, row, diagram, ...extraGates) => assertThat(circuit( diagram, ...ownExtraGates, ...extraGates).gateAtLocIsDisabledReason(col, row)).isNotEqualTo(undefined)
@param {!int} col @param {!int} row @param {!string} diagram @param {![!string, !Gate]} extraGates
bad
javascript
Strilanc/Quirk
test/circuit/CircuitDefinition.test.js
https://github.com/Strilanc/Quirk/blob/master/test/circuit/CircuitDefinition.test.js
Apache-2.0
bad = (col, row, diagram, ...extraGates) => assertThat(circuit( diagram, ...ownExtraGates, ...extraGates).gateAtLocIsDisabledReason(col, row)).isNotEqualTo(undefined)
@param {!int} col @param {!int} row @param {!string} diagram @param {![!string, !Gate]} extraGates
bad
javascript
Strilanc/Quirk
test/circuit/CircuitDefinition.test.js
https://github.com/Strilanc/Quirk/blob/master/test/circuit/CircuitDefinition.test.js
Apache-2.0
good = (col, row, diagram, ...extraGates) => assertThat(circuit( diagram, ...ownExtraGates, ...extraGates).gateAtLocIsDisabledReason(col, row)).isEqualTo(undefined)
@param {!int} col @param {!int} row @param {!string} diagram @param {![!string, !Gate]} extraGates
good
javascript
Strilanc/Quirk
test/circuit/CircuitDefinition.test.js
https://github.com/Strilanc/Quirk/blob/master/test/circuit/CircuitDefinition.test.js
Apache-2.0
good = (col, row, diagram, ...extraGates) => assertThat(circuit( diagram, ...ownExtraGates, ...extraGates).gateAtLocIsDisabledReason(col, row)).isEqualTo(undefined)
@param {!int} col @param {!int} row @param {!string} diagram @param {![!string, !Gate]} extraGates
good
javascript
Strilanc/Quirk
test/circuit/CircuitDefinition.test.js
https://github.com/Strilanc/Quirk/blob/master/test/circuit/CircuitDefinition.test.js
Apache-2.0
query = (diagram, ...extraGates) => circuit( diagram, ...ownExtraGates, ...extraGates).getUnmetContextKeys()
@param {!int} col @param {!int} row @param {!string} diagram @param {![!string, !Gate]} extraGates
query
javascript
Strilanc/Quirk
test/circuit/CircuitDefinition.test.js
https://github.com/Strilanc/Quirk/blob/master/test/circuit/CircuitDefinition.test.js
Apache-2.0
query = (diagram, ...extraGates) => circuit( diagram, ...ownExtraGates, ...extraGates).getUnmetContextKeys()
@param {!int} col @param {!int} row @param {!string} diagram @param {![!string, !Gate]} extraGates
query
javascript
Strilanc/Quirk
test/circuit/CircuitDefinition.test.js
https://github.com/Strilanc/Quirk/blob/master/test/circuit/CircuitDefinition.test.js
Apache-2.0
bad = (col, row, diagram, ...extraGates) => assertThat(circuit(diagram, ...extraGates).gateAtLocIsDisabledReason(col, row)).isNotEqualTo(undefined)
@param {!int} col @param {!int} row @param {!string} diagram @param {![!string, !Gate]} extraGates
bad
javascript
Strilanc/Quirk
test/circuit/CircuitDefinition.test.js
https://github.com/Strilanc/Quirk/blob/master/test/circuit/CircuitDefinition.test.js
Apache-2.0
bad = (col, row, diagram, ...extraGates) => assertThat(circuit(diagram, ...extraGates).gateAtLocIsDisabledReason(col, row)).isNotEqualTo(undefined)
@param {!int} col @param {!int} row @param {!string} diagram @param {![!string, !Gate]} extraGates
bad
javascript
Strilanc/Quirk
test/circuit/CircuitDefinition.test.js
https://github.com/Strilanc/Quirk/blob/master/test/circuit/CircuitDefinition.test.js
Apache-2.0
good = (col, row, diagram, ...extraGates) => assertThat(circuit(diagram, ...extraGates).gateAtLocIsDisabledReason(col, row)).isEqualTo(undefined)
@param {!int} col @param {!int} row @param {!string} diagram @param {![!string, !Gate]} extraGates
good
javascript
Strilanc/Quirk
test/circuit/CircuitDefinition.test.js
https://github.com/Strilanc/Quirk/blob/master/test/circuit/CircuitDefinition.test.js
Apache-2.0
good = (col, row, diagram, ...extraGates) => assertThat(circuit(diagram, ...extraGates).gateAtLocIsDisabledReason(col, row)).isEqualTo(undefined)
@param {!int} col @param {!int} row @param {!string} diagram @param {![!string, !Gate]} extraGates
good
javascript
Strilanc/Quirk
test/circuit/CircuitDefinition.test.js
https://github.com/Strilanc/Quirk/blob/master/test/circuit/CircuitDefinition.test.js
Apache-2.0
reconstructMatrixFromGateCustomOperation = (gate, time) => { if (gate.customOperation === undefined) { return undefined; } let bit = 0; let numQubits = gate.height; let n = 1 << numQubits; let control = CircuitShaders.controlMask(Controls.NONE).toBoolTexture(numQubits); let cols = [...
@param {!Gate} gate @param {!number} time @returns {undefined|!Matrix}
reconstructMatrixFromGateCustomOperation
javascript
Strilanc/Quirk
test/gates/AllGates.test.js
https://github.com/Strilanc/Quirk/blob/master/test/gates/AllGates.test.js
Apache-2.0
reconstructMatrixFromGateCustomOperation = (gate, time) => { if (gate.customOperation === undefined) { return undefined; } let bit = 0; let numQubits = gate.height; let n = 1 << numQubits; let control = CircuitShaders.controlMask(Controls.NONE).toBoolTexture(numQubits); let cols = [...
@param {!Gate} gate @param {!number} time @returns {undefined|!Matrix}
reconstructMatrixFromGateCustomOperation
javascript
Strilanc/Quirk
test/gates/AllGates.test.js
https://github.com/Strilanc/Quirk/blob/master/test/gates/AllGates.test.js
Apache-2.0
displayedCircuit = (diagramText, ...extraGateEntries) => DisplayedCircuit.fromTextDiagram( new Map([ ...COMMON_GATES.entries(), ...extraGateEntries ]), diagramText)
@param {!string} diagramText @param {!Array<*>} extraGateEntries @returns {!{circuit: !DisplayedCircuit, pts: !Array.<!Point>}}
displayedCircuit
javascript
Strilanc/Quirk
test/ui/DisplayedCircuit.test.js
https://github.com/Strilanc/Quirk/blob/master/test/ui/DisplayedCircuit.test.js
Apache-2.0
displayedCircuit = (diagramText, ...extraGateEntries) => DisplayedCircuit.fromTextDiagram( new Map([ ...COMMON_GATES.entries(), ...extraGateEntries ]), diagramText)
@param {!string} diagramText @param {!Array<*>} extraGateEntries @returns {!{circuit: !DisplayedCircuit, pts: !Array.<!Point>}}
displayedCircuit
javascript
Strilanc/Quirk
test/ui/DisplayedCircuit.test.js
https://github.com/Strilanc/Quirk/blob/master/test/ui/DisplayedCircuit.test.js
Apache-2.0
simulateDrag = (diagramText, options={}, ...extraGateEntries) => { let duplicate = options.duplicate || false; let wholeColumn = options.wholeColumn || false; let {circuit: beforeGrab, pts} = displayedCircuit(diagramText, ...extraGateEntries); let {newCircuit: afterGrab, newHand: fullHand} = be...
@param {!string} diagramText @param {undefined|!{duplicate: undefined|!boolean, wholeColumn: undefined|!boolean}} options @param {!Array<*>} extraGateEntries @returns {{ beforeGrab: !DisplayedCircuit, afterGrab: !DisplayedCircuit, hovers: !Array.<!DisplayedCircuit>, afterDrop: !DisplayedCircuit, afterDropAndT...
simulateDrag
javascript
Strilanc/Quirk
test/ui/DisplayedCircuit.test.js
https://github.com/Strilanc/Quirk/blob/master/test/ui/DisplayedCircuit.test.js
Apache-2.0
simulateDrag = (diagramText, options={}, ...extraGateEntries) => { let duplicate = options.duplicate || false; let wholeColumn = options.wholeColumn || false; let {circuit: beforeGrab, pts} = displayedCircuit(diagramText, ...extraGateEntries); let {newCircuit: afterGrab, newHand: fullHand} = be...
@param {!string} diagramText @param {undefined|!{duplicate: undefined|!boolean, wholeColumn: undefined|!boolean}} options @param {!Array<*>} extraGateEntries @returns {{ beforeGrab: !DisplayedCircuit, afterGrab: !DisplayedCircuit, hovers: !Array.<!DisplayedCircuit>, afterDrop: !DisplayedCircuit, afterDropAndT...
simulateDrag
javascript
Strilanc/Quirk
test/ui/DisplayedCircuit.test.js
https://github.com/Strilanc/Quirk/blob/master/test/ui/DisplayedCircuit.test.js
Apache-2.0
function perfGoal(name, targetDuration, method, arg=undefined, cleanup=undefined) { //noinspection JSUnusedGlobalSymbols _knownPerfTests.push({name, method: () => { let dt = _measureDuration(method, arg, targetDuration.duration_nanos); if (cleanup !== undefined) { cleanup(arg); ...
@param {!string} name @param {!{duration_nanos: !int, description: !string}} targetDuration @param {!function(*):*} method @param {undefined|*=undefined} arg @param {!function(*):void} cleanup
perfGoal
javascript
Strilanc/Quirk
test_perf/TestPerfUtil.js
https://github.com/Strilanc/Quirk/blob/master/test_perf/TestPerfUtil.js
Apache-2.0
function _pad(obj, length) { let v = `${obj}`; return ' '.repeat(Math.max(0, length - v.length)) + v; }
@param {!string} name @param {!{duration_nanos: !int, description: !string}} targetDuration @param {!function(*):*} method @param {undefined|*=undefined} arg @param {!function(*):void} cleanup
_pad
javascript
Strilanc/Quirk
test_perf/TestPerfUtil.js
https://github.com/Strilanc/Quirk/blob/master/test_perf/TestPerfUtil.js
Apache-2.0
function _proportionDesc(proportion) { return `[${_proportionBar(proportion)}] finished in ${_pad(Math.round(proportion*100), 2)}%`; }
@param {!string} name @param {!{duration_nanos: !int, description: !string}} targetDuration @param {!function(*):*} method @param {undefined|*=undefined} arg @param {!function(*):void} cleanup
_proportionDesc
javascript
Strilanc/Quirk
test_perf/TestPerfUtil.js
https://github.com/Strilanc/Quirk/blob/master/test_perf/TestPerfUtil.js
Apache-2.0
function _proportionBar(proportion, length=20) { if (proportion > 1) { return '!'.repeat(length); } let n = Math.round(proportion * length); return '#'.repeat(n) + ' '.repeat(length - n); }
@param {!string} name @param {!{duration_nanos: !int, description: !string}} targetDuration @param {!function(*):*} method @param {undefined|*=undefined} arg @param {!function(*):void} cleanup
_proportionBar
javascript
Strilanc/Quirk
test_perf/TestPerfUtil.js
https://github.com/Strilanc/Quirk/blob/master/test_perf/TestPerfUtil.js
Apache-2.0
function _measureDuration(method, arg, expected_nanos_hint) { let ms = 1.0e6; let repeats = expected_nanos_hint < 5 * ms ? 100 : expected_nanos_hint < 30 * ms ? 50 : 10; // Dry run to get any one-time initialization done. method(arg); let t0 = window.performance.now(); for (let ...
@param {!string} name @param {!{duration_nanos: !int, description: !string}} targetDuration @param {!function(*):*} method @param {undefined|*=undefined} arg @param {!function(*):void} cleanup
_measureDuration
javascript
Strilanc/Quirk
test_perf/TestPerfUtil.js
https://github.com/Strilanc/Quirk/blob/master/test_perf/TestPerfUtil.js
Apache-2.0
addExtensions(extensions) { _.forOwn(extensions, (components, extensionId) => { WidgetsRegistry.addExtension(extensionId, components) }) return WidgetsRegistry }
Register multiple extensions components. @param {Object} extensions
addExtensions
javascript
plouc/mozaik
packages/ui/src/WidgetsRegistry.js
https://github.com/plouc/mozaik/blob/master/packages/ui/src/WidgetsRegistry.js
MIT
addExtension(extension, components) { _.forOwn(components, (component, widget) => { WidgetsRegistry.add(extension, widget, component) }) return WidgetsRegistry }
Register an extension components. @param {String} extensionId @param {Object} components @returns {WidgetsRegistry}
addExtension
javascript
plouc/mozaik
packages/ui/src/WidgetsRegistry.js
https://github.com/plouc/mozaik/blob/master/packages/ui/src/WidgetsRegistry.js
MIT
add(extension, widget, component) { if (!registry.hasOwnProperty(extension)) { registry[extension] = {} } registry[extension][widget] = component return WidgetsRegistry }
@param {string} extension @param {string} widget @param {Function} component @returns {WidgetsRegistry}
add
javascript
plouc/mozaik
packages/ui/src/WidgetsRegistry.js
https://github.com/plouc/mozaik/blob/master/packages/ui/src/WidgetsRegistry.js
MIT
has(extension, widget) { return registry.hasOwnProperty(extension) && registry[extension].hasOwnProperty(widget) }
@param {string} extension @param {string} widget @return {boolean}
has
javascript
plouc/mozaik
packages/ui/src/WidgetsRegistry.js
https://github.com/plouc/mozaik/blob/master/packages/ui/src/WidgetsRegistry.js
MIT
getComponent(extension, widget) { if (!WidgetsRegistry.has(extension, widget)) { throw new Error(`No widget "${widget}" defined for extension "${extension}"`) } return registry[extension][widget] }
@param {string} extension @param {string} widget @return {Function}
getComponent
javascript
plouc/mozaik
packages/ui/src/WidgetsRegistry.js
https://github.com/plouc/mozaik/blob/master/packages/ui/src/WidgetsRegistry.js
MIT
widgetsCount() { let count = 0 for (let ext in registry) { count += Object.keys(registry[ext]).length } return count }
@param {string} extension @param {string} widget @return {Function}
widgetsCount
javascript
plouc/mozaik
packages/ui/src/WidgetsRegistry.js
https://github.com/plouc/mozaik/blob/master/packages/ui/src/WidgetsRegistry.js
MIT
formatUptime = uptime => { let parts = [] let remaining = Math.round(uptime) if (remaining >= SECONDS_PER_DAY) { parts.push(`${Math.floor(remaining / SECONDS_PER_DAY)}d`) remaining = remaining % SECONDS_PER_DAY } if (remaining >= SECONDS_PER_HOUR) { parts.push(`${Math.floor...
Format uptime (seconds) to human readable output. @param {Number} uptime @returns {string}
formatUptime
javascript
plouc/mozaik
packages/ui/src/components/Inspector.js
https://github.com/plouc/mozaik/blob/master/packages/ui/src/components/Inspector.js
MIT
formatUptime = uptime => { let parts = [] let remaining = Math.round(uptime) if (remaining >= SECONDS_PER_DAY) { parts.push(`${Math.floor(remaining / SECONDS_PER_DAY)}d`) remaining = remaining % SECONDS_PER_DAY } if (remaining >= SECONDS_PER_HOUR) { parts.push(`${Math.floor...
Format uptime (seconds) to human readable output. @param {Number} uptime @returns {string}
formatUptime
javascript
plouc/mozaik
packages/ui/src/components/Inspector.js
https://github.com/plouc/mozaik/blob/master/packages/ui/src/components/Inspector.js
MIT
static getApiRequest() { return { id: 'mozaik.inspector' } }
Format uptime (seconds) to human readable output. @param {Number} uptime @returns {string}
getApiRequest
javascript
plouc/mozaik
packages/ui/src/components/Inspector.js
https://github.com/plouc/mozaik/blob/master/packages/ui/src/components/Inspector.js
MIT
function shallowEqual(a, b) { if (a === b) return true let countA = 0 let countB = 0 for (let key in a) { if (hasOwn.call(a, key) && a[key] !== b[key]) return false countA++ } for (let key in b) { if (hasOwn.call(b, key)) countB++ } return countA === countB }
from https://raw.githubusercontent.com/reactjs/react-redux/master/src/utils/shallowEqual.js
shallowEqual
javascript
plouc/mozaik
packages/ui/src/lib/shallowEqual.js
https://github.com/plouc/mozaik/blob/master/packages/ui/src/lib/shallowEqual.js
MIT
constructor(body, headers, statusCode) { const message = 'An error occurred while communicating with Spotify\'s Web API.\n' + 'Details: ' + body.error.message + '.'; super(body, headers, statusCode, message); }
Regular Error { status : <integer>, message : <string> }
constructor
javascript
thelinmichael/spotify-web-api-node
src/response-error.js
https://github.com/thelinmichael/spotify-web-api-node/blob/master/src/response-error.js
MIT
constructor(body, headers, statusCode) { const message = 'An error occurred while communicating with Spotify\'s Web API.\n' + 'Details: ' + body.error.message + (body.error.reason ? ' ' + body.error.reason + '.' : '.'); super(body, headers, statusCode, message); }
Player Error { status : <integer>, message : <string>, reason : <string> }
constructor
javascript
thelinmichael/spotify-web-api-node
src/response-error.js
https://github.com/thelinmichael/spotify-web-api-node/blob/master/src/response-error.js
MIT
variableDefinitionByName = name => (this.props.definition.variableDefinitions || []).find( varDef => varDef.variable.name.value === name, )
1. Find current operation variables 2. Find current arg value 3. Create a new variable 4. Replace current arg value with variable 5. Add variable to operation
variableDefinitionByName
javascript
OneGraph/graphiql-explorer
src/Explorer.js
https://github.com/OneGraph/graphiql-explorer/blob/master/src/Explorer.js
MIT
variableDefinitionByName = name => (this.props.definition.variableDefinitions || []).find( varDef => varDef.variable.name.value === name, )
1. Find current operation variables 2. Find current arg value 3. Create a new variable 4. Replace current arg value with variable 5. Add variable to operation
variableDefinitionByName
javascript
OneGraph/graphiql-explorer
src/Explorer.js
https://github.com/OneGraph/graphiql-explorer/blob/master/src/Explorer.js
MIT
Variable(node) { const varName = node.name.value; const varDef = variableDefinitionByName(varName); subVariableUsageCountByName[varName] = subVariableUsageCountByName[varName] + 1 || 1; if (!varDef) { return; } return...
In the process of devariabilizing descendent selections, we may have caused their variable definitions to become unused. Keep track and remove any variable definitions with 1 or fewer usages.
Variable
javascript
OneGraph/graphiql-explorer
src/Explorer.js
https://github.com/OneGraph/graphiql-explorer/blob/master/src/Explorer.js
MIT
Variable(node) { if (node.name.value === variableName) { variableUseCount = variableUseCount + 1; } }
1. Find the current variable definition in the operation def 2. Extract its value 3. Replace the current arg value 4. Visit the resulting operation to see if there are any other usages of the variable 5. If not, remove the variableDefinition
Variable
javascript
OneGraph/graphiql-explorer
src/Explorer.js
https://github.com/OneGraph/graphiql-explorer/blob/master/src/Explorer.js
MIT
if ( isRequiredInputField(field) || (makeDefaultArg && makeDefaultArg(parentField, field)) ) { const fieldType = unwrapInputType(field.type); if (isInputObjectType(fieldType)) { const fields = fieldType.getFields(); nodes.push({ kind: 'ObjectField', name: ...
1. Find the current variable definition in the operation def 2. Extract its value 3. Replace the current arg value 4. Visit the resulting operation to see if there are any other usages of the variable 5. If not, remove the variableDefinition
if
javascript
OneGraph/graphiql-explorer
src/Explorer.js
https://github.com/OneGraph/graphiql-explorer/blob/master/src/Explorer.js
MIT
if (parseQueryMemoize) { // Most likely a temporarily invalid query while they type return parseQueryMemoize[1]; }
1. Find the current variable definition in the operation def 2. Extract its value 3. Replace the current arg value 4. Visit the resulting operation to see if there are any other usages of the variable 5. If not, remove the variableDefinition
if
javascript
OneGraph/graphiql-explorer
src/Explorer.js
https://github.com/OneGraph/graphiql-explorer/blob/master/src/Explorer.js
MIT
function clearDist() { let cleared = false return { async buildStart() { if (cleared) return cleared = true try { if (existsSync(path.resolve('dist'))) await fs.rm(path.resolve('dist'), { recursive: true }) await fs.mkdir(path.resolve('dist')) console.log('...
Deletes the dist/ folder and then makes a new directory. Equivalent to `rm -r dist && mkdir dist`
clearDist
javascript
dayhaysoos/use-shopping-cart
use-shopping-cart/rollup.config.js
https://github.com/dayhaysoos/use-shopping-cart/blob/master/use-shopping-cart/rollup.config.js
MIT
async buildStart() { if (cleared) return cleared = true try { if (existsSync(path.resolve('dist'))) await fs.rm(path.resolve('dist'), { recursive: true }) await fs.mkdir(path.resolve('dist')) console.log('Cleared dist/ folder.') } catch (error) { conso...
Deletes the dist/ folder and then makes a new directory. Equivalent to `rm -r dist && mkdir dist`
buildStart
javascript
dayhaysoos/use-shopping-cart
use-shopping-cart/rollup.config.js
https://github.com/dayhaysoos/use-shopping-cart/blob/master/use-shopping-cart/rollup.config.js
MIT
function addUseClientDirective() { return { name: 'add-use-client-directive', banner() { return "'use client';" } } }
Deletes the dist/ folder and then makes a new directory. Equivalent to `rm -r dist && mkdir dist`
addUseClientDirective
javascript
dayhaysoos/use-shopping-cart
use-shopping-cart/rollup.config.js
https://github.com/dayhaysoos/use-shopping-cart/blob/master/use-shopping-cart/rollup.config.js
MIT
banner() { return "'use client';" }
Deletes the dist/ folder and then makes a new directory. Equivalent to `rm -r dist && mkdir dist`
banner
javascript
dayhaysoos/use-shopping-cart
use-shopping-cart/rollup.config.js
https://github.com/dayhaysoos/use-shopping-cart/blob/master/use-shopping-cart/rollup.config.js
MIT
get aliases() { return alias({ entries: { uuid: 'uuid/dist/esm-browser/index.js' } }) }
Deletes the dist/ folder and then makes a new directory. Equivalent to `rm -r dist && mkdir dist`
aliases
javascript
dayhaysoos/use-shopping-cart
use-shopping-cart/rollup.config.js
https://github.com/dayhaysoos/use-shopping-cart/blob/master/use-shopping-cart/rollup.config.js
MIT
function typeOf(value) { if (value === undefined) return 'undefined' if (value === null) return 'null' return value.constructor.name }
Returns the constructor name of any value. @param {any} value @returns string
typeOf
javascript
dayhaysoos/use-shopping-cart
use-shopping-cart/core/middleware/helpers.js
https://github.com/dayhaysoos/use-shopping-cart/blob/master/use-shopping-cart/core/middleware/helpers.js
MIT
constructor({ property, method, expected, received }) { const plural = Array.isArray(expected) const expectedString = plural ? `are ${expected.map((v) => JSON.stringify(v)).join(', ')}` : `is ${JSON.stringify(expected)}` const methodString = typeof method === 'string' ? ` in ${method}()` : '' ...
Returns the constructor name of any value. @param {any} value @returns string
constructor
javascript
dayhaysoos/use-shopping-cart
use-shopping-cart/core/middleware/helpers.js
https://github.com/dayhaysoos/use-shopping-cart/blob/master/use-shopping-cart/core/middleware/helpers.js
MIT