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 |
|---|---|---|---|---|---|---|---|
_addConstantFact (fact) {
this.factMap.set(fact.id, fact)
this._setFactValue(fact, {}, fact.value)
} | Registers fact with the almanac
@param {[type]} fact [description] | _addConstantFact | javascript | CacheControl/json-rules-engine | src/almanac.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/almanac.js | ISC |
_setFactValue (fact, params, value) {
const cacheKey = fact.getCacheKey(params)
const factValue = Promise.resolve(value)
if (cacheKey) {
this.factResultsCache.set(cacheKey, factValue)
}
return factValue
} | Sets the computed value of a fact
@param {Fact} fact
@param {Object} params - values for differentiating this fact value from others, used for cache key
@param {Mixed} value - computed value | _setFactValue | javascript | CacheControl/json-rules-engine | src/almanac.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/almanac.js | ISC |
addFact (id, valueOrMethod, options) {
let factId = id
let fact
if (id instanceof Fact) {
factId = id.id
fact = id
} else {
fact = new Fact(id, valueOrMethod, options)
}
debug('almanac::addFact', { id: factId })
this.factMap.set(factId, fact)
if (fact.isConstant()) {
... | Add a fact definition to the engine. Facts are called by rules as they are evaluated.
@param {object|Fact} id - fact identifier or instance of Fact
@param {function} definitionFunc - function to be called when computing the fact value for a given rule
@param {Object} options - options to initialize the fact with. used... | addFact | javascript | CacheControl/json-rules-engine | src/almanac.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/almanac.js | ISC |
addRuntimeFact (factId, value) {
debug('almanac::addRuntimeFact', { id: factId })
const fact = new Fact(factId, value)
return this._addConstantFact(fact)
} | Adds a constant fact during runtime. Can be used mid-run() to add additional information
@deprecated use addFact
@param {String} fact - fact identifier
@param {Mixed} value - constant value of the fact | addRuntimeFact | javascript | CacheControl/json-rules-engine | src/almanac.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/almanac.js | ISC |
factValue (factId, params = {}, path = '') {
let factValuePromise
const fact = this._getFact(factId)
if (fact === undefined) {
if (this.allowUndefinedFacts) {
return Promise.resolve(undefined)
} else {
return Promise.reject(new UndefinedFactError(`Undefined fact: ${factId}`))
... | Returns the value of a fact, based on the given parameters. Utilizes the 'almanac' maintained
by the engine, which cache's fact computations based on parameters provided
@param {string} factId - fact identifier
@param {Object} params - parameters to feed into the fact. By default, these will also be used to compute... | factValue | javascript | CacheControl/json-rules-engine | src/almanac.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/almanac.js | ISC |
toJSON (stringify = true) {
const props = {}
if (this.priority) {
props.priority = this.priority
}
if (this.name) {
props.name = this.name
}
const oper = Condition.booleanOperator(this)
if (oper) {
if (Array.isArray(this[oper])) {
props[oper] = this[oper].map((c) =>... | Converts the condition into a json-friendly structure
@param {Boolean} stringify - whether to return as a json string
@returns {string,object} json string or json-friendly object | toJSON | javascript | CacheControl/json-rules-engine | src/condition.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/condition.js | ISC |
evaluate (almanac, operatorMap) {
if (!almanac) return Promise.reject(new Error('almanac required'))
if (!operatorMap) return Promise.reject(new Error('operatorMap required'))
if (this.isBooleanOperator()) { return Promise.reject(new Error('Cannot evaluate() a boolean condition')) }
const op = operator... | Takes the fact result and compares it to the condition 'value', using the operator
LHS OPER RHS
<fact + params + path> <operator> <value>
@param {Almanac} almanac
@param {Map} operatorMap - map of available operators, keyed by operator name
@returns {Boolean} - evaluation result | evaluate | javascript | CacheControl/json-rules-engine | src/condition.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/condition.js | ISC |
static booleanOperator (condition) {
if (Object.prototype.hasOwnProperty.call(condition, 'any')) {
return 'any'
} else if (Object.prototype.hasOwnProperty.call(condition, 'all')) {
return 'all'
} else if (Object.prototype.hasOwnProperty.call(condition, 'not')) {
return 'not'
}
} | Returns the boolean operator for the condition
If the condition is not a boolean condition, the result will be 'undefined'
@return {string 'all', 'any', or 'not'} | booleanOperator | javascript | CacheControl/json-rules-engine | src/condition.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/condition.js | ISC |
booleanOperator () {
return Condition.booleanOperator(this)
} | Returns the condition's boolean operator
Instance version of Condition.isBooleanOperator
@returns {string,undefined} - 'any', 'all', 'not' or undefined (if not a boolean condition) | booleanOperator | javascript | CacheControl/json-rules-engine | src/condition.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/condition.js | ISC |
isBooleanOperator () {
return Condition.booleanOperator(this) !== undefined
} | Whether the operator is boolean ('all', 'any', 'not')
@returns {Boolean} | isBooleanOperator | javascript | CacheControl/json-rules-engine | src/condition.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/condition.js | ISC |
isConditionReference () {
return Object.prototype.hasOwnProperty.call(this, 'condition')
} | Whether the condition represents a reference to a condition
@returns {Boolean} | isConditionReference | javascript | CacheControl/json-rules-engine | src/condition.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/condition.js | ISC |
constructor (rules = [], options = {}) {
super()
this.rules = []
this.allowUndefinedFacts = options.allowUndefinedFacts || false
this.allowUndefinedConditions = options.allowUndefinedConditions || false
this.replaceFactsInEventParams = options.replaceFactsInEventParams || false
this.pathResolver... | Returns a new Engine instance
@param {Rule[]} rules - array of rules to initialize with | constructor | javascript | CacheControl/json-rules-engine | src/engine.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/engine.js | ISC |
updateRule (rule) {
const ruleIndex = this.rules.findIndex(ruleInEngine => ruleInEngine.name === rule.name)
if (ruleIndex > -1) {
this.rules.splice(ruleIndex, 1)
this.addRule(rule)
this.prioritizedRules = null
} else {
throw new Error('Engine: updateRule() rule not found')
}
} | update a rule in the engine
@param {object|Rule} rule - rule definition. Must be a instance of Rule | updateRule | javascript | CacheControl/json-rules-engine | src/engine.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/engine.js | ISC |
removeRule (rule) {
let ruleRemoved = false
if (!(rule instanceof Rule)) {
const filteredRules = this.rules.filter(ruleInEngine => ruleInEngine.name !== rule)
ruleRemoved = filteredRules.length !== this.rules.length
this.rules = filteredRules
} else {
const index = this.rules.indexOf... | Remove a rule from the engine
@param {object|Rule|string} rule - rule definition. Must be a instance of Rule | removeRule | javascript | CacheControl/json-rules-engine | src/engine.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/engine.js | ISC |
setCondition (name, conditions) {
if (!name) throw new Error('Engine: setCondition() requires name')
if (!conditions) throw new Error('Engine: setCondition() requires conditions')
if (!Object.prototype.hasOwnProperty.call(conditions, 'all') && !Object.prototype.hasOwnProperty.call(conditions, 'any') && !Obj... | sets a condition that can be referenced by the given name.
If a condition with the given name has already been set this will replace it.
@param {string} name - the name of the condition to be referenced by rules.
@param {object} conditions - the conditions to use when the condition is referenced. | setCondition | javascript | CacheControl/json-rules-engine | src/engine.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/engine.js | ISC |
removeCondition (name) {
return this.conditions.delete(name)
} | Removes a condition that has previously been added to this engine
@param {string} name - the name of the condition to remove.
@returns true if the condition existed, otherwise false | removeCondition | javascript | CacheControl/json-rules-engine | src/engine.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/engine.js | ISC |
addOperator (operatorOrName, cb) {
this.operators.addOperator(operatorOrName, cb)
} | Add a custom operator definition
@param {string} operatorOrName - operator identifier within the condition; i.e. instead of 'equals', 'greaterThan', etc
@param {function(factValue, jsonValue)} callback - the method to execute when the operator is encountered. | addOperator | javascript | CacheControl/json-rules-engine | src/engine.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/engine.js | ISC |
removeOperator (operatorOrName) {
return this.operators.removeOperator(operatorOrName)
} | Remove a custom operator definition
@param {string} operatorOrName - operator identifier within the condition; i.e. instead of 'equals', 'greaterThan', etc | removeOperator | javascript | CacheControl/json-rules-engine | src/engine.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/engine.js | ISC |
addOperatorDecorator (decoratorOrName, cb) {
this.operators.addOperatorDecorator(decoratorOrName, cb)
} | Add a custom operator decorator
@param {string} decoratorOrName - decorator identifier within the condition; i.e. instead of 'someFact', 'everyValue', etc
@param {function(factValue, jsonValue, next)} callback - the method to execute when the decorator is encountered. | addOperatorDecorator | javascript | CacheControl/json-rules-engine | src/engine.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/engine.js | ISC |
removeOperatorDecorator (decoratorOrName) {
return this.operators.removeOperatorDecorator(decoratorOrName)
} | Remove a custom operator decorator
@param {string} decoratorOrName - decorator identifier within the condition; i.e. instead of 'someFact', 'everyValue', etc | removeOperatorDecorator | javascript | CacheControl/json-rules-engine | src/engine.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/engine.js | ISC |
addFact (id, valueOrMethod, options) {
let factId = id
let fact
if (id instanceof Fact) {
factId = id.id
fact = id
} else {
fact = new Fact(id, valueOrMethod, options)
}
debug('engine::addFact', { id: factId })
this.facts.set(factId, fact)
return this
} | Add a fact definition to the engine. Facts are called by rules as they are evaluated.
@param {object|Fact} id - fact identifier or instance of Fact
@param {function} definitionFunc - function to be called when computing the fact value for a given rule
@param {Object} options - options to initialize the fact with. used... | addFact | javascript | CacheControl/json-rules-engine | src/engine.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/engine.js | ISC |
removeFact (factOrId) {
let factId
if (!(factOrId instanceof Fact)) {
factId = factOrId
} else {
factId = factOrId.id
}
return this.facts.delete(factId)
} | Remove a fact definition to the engine. Facts are called by rules as they are evaluated.
@param {object|Fact} id - fact identifier or instance of Fact | removeFact | javascript | CacheControl/json-rules-engine | src/engine.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/engine.js | ISC |
prioritizeRules () {
if (!this.prioritizedRules) {
const ruleSets = this.rules.reduce((sets, rule) => {
const priority = rule.priority
if (!sets[priority]) sets[priority] = []
sets[priority].push(rule)
return sets
}, {})
this.prioritizedRules = Object.keys(ruleSets)... | Iterates over the engine rules, organizing them by highest -> lowest priority
@return {Rule[][]} two dimensional array of Rules.
Each outer array element represents a single priority(integer). Inner array is
all rules with that priority. | prioritizeRules | javascript | CacheControl/json-rules-engine | src/engine.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/engine.js | ISC |
getFact (factId) {
return this.facts.get(factId)
} | Returns a fact by fact-id
@param {string} factId - fact identifier
@return {Fact} fact instance, or undefined if no such fact exists | getFact | javascript | CacheControl/json-rules-engine | src/engine.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/engine.js | ISC |
evaluateRules (ruleArray, almanac) {
return Promise.all(ruleArray.map((rule) => {
if (this.status !== RUNNING) {
debug('engine::run, skipping remaining rules', { status: this.status })
return Promise.resolve()
}
return rule.evaluate(almanac).then((ruleResult) => {
debug('en... | Runs an array of rules
@param {Rule[]} array of rules to be evaluated
@return {Promise} resolves when all rules in the array have been evaluated | evaluateRules | javascript | CacheControl/json-rules-engine | src/engine.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/engine.js | ISC |
run (runtimeFacts = {}, runOptions = {}) {
debug('engine::run started')
this.status = RUNNING
const almanac = runOptions.almanac || new Almanac({
allowUndefinedFacts: this.allowUndefinedFacts,
pathResolver: this.pathResolver
})
this.facts.forEach(fact => {
almanac.addFact(fact)
... | Runs the rules engine
@param {Object} runtimeFacts - fact values known at runtime
@param {Object} runOptions - run options
@return {Promise} resolves when the engine has completed running | run | javascript | CacheControl/json-rules-engine | src/engine.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/engine.js | ISC |
calculate (params, almanac) {
// if constant fact w/set value, return immediately
if (Object.prototype.hasOwnProperty.call(this, 'value')) {
return this.value
}
return this.calculationMethod(params, almanac)
} | Return the fact value, based on provided parameters
@param {object} params
@param {Almanac} almanac
@return {any} calculation method results | calculate | javascript | CacheControl/json-rules-engine | src/fact.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/fact.js | ISC |
static hashFromObject (obj) {
return hash(obj)
} | Return a cache key (MD5 string) based on parameters
@param {object} obj - properties to generate a hash key from
@return {string} MD5 string based on the hash'd object | hashFromObject | javascript | CacheControl/json-rules-engine | src/fact.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/fact.js | ISC |
defaultCacheKeys (id, params) {
return { params, id }
} | Default properties to use when caching a fact
Assumes every fact is a pure function, whose computed value will only
change when input params are modified
@param {string} id - fact unique identifer
@param {object} params - parameters passed to fact calcution method
@return {object} id + params | defaultCacheKeys | javascript | CacheControl/json-rules-engine | src/fact.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/fact.js | ISC |
getCacheKey (params) {
if (this.options.cache === true) {
const cacheProperties = this.cacheKeyMethod(this.id, params)
const hash = Fact.hashFromObject(cacheProperties)
return hash
}
} | Generates the fact's cache key(MD5 string)
Returns nothing if the fact's caching has been disabled
@param {object} params - parameters that would be passed to the computation method
@return {string} cache key | getCacheKey | javascript | CacheControl/json-rules-engine | src/fact.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/fact.js | ISC |
constructor (name, cb, factValueValidator) {
this.name = String(name)
if (!name) throw new Error('Missing decorator name')
if (typeof cb !== 'function') throw new Error('Missing decorator callback')
this.cb = cb
this.factValueValidator = factValueValidator
if (!this.factValueValidator) this.fact... | Constructor
@param {string} name - decorator identifier
@param {function(factValue, jsonValue, next)} callback - callback that takes the next operator as a parameter
@param {function} [factValueValidator] - optional validator for asserting the data type of the fact
@returns {OperatorDecorator} - instance | constructor | javascript | CacheControl/json-rules-engine | src/operator-decorator.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/operator-decorator.js | ISC |
decorate (operator) {
const next = operator.evaluate.bind(operator)
return new Operator(
`${this.name}:${operator.name}`,
(factValue, jsonValue) => {
return this.cb(factValue, jsonValue, next)
},
this.factValueValidator
)
} | Takes the fact result and compares it to the condition 'value', using the callback
@param {Operator} operator - fact result
@returns {Operator} - whether the values pass the operator test | decorate | javascript | CacheControl/json-rules-engine | src/operator-decorator.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/operator-decorator.js | ISC |
addOperator (operatorOrName, cb) {
let operator
if (operatorOrName instanceof Operator) {
operator = operatorOrName
} else {
operator = new Operator(operatorOrName, cb)
}
debug('operatorMap::addOperator', { name: operator.name })
this.operators.set(operator.name, operator)
} | Add a custom operator definition
@param {string} operatorOrName - operator identifier within the condition; i.e. instead of 'equals', 'greaterThan', etc
@param {function(factValue, jsonValue)} callback - the method to execute when the operator is encountered. | addOperator | javascript | CacheControl/json-rules-engine | src/operator-map.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/operator-map.js | ISC |
removeOperator (operatorOrName) {
let operatorName
if (operatorOrName instanceof Operator) {
operatorName = operatorOrName.name
} else {
operatorName = operatorOrName
}
// Delete all the operators that end in :operatorName these
// were decorated on-the-fly leveraging this operator
... | Remove a custom operator definition
@param {string} operatorOrName - operator identifier within the condition; i.e. instead of 'equals', 'greaterThan', etc
@param {function(factValue, jsonValue)} callback - the method to execute when the operator is encountered. | removeOperator | javascript | CacheControl/json-rules-engine | src/operator-map.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/operator-map.js | ISC |
addOperatorDecorator (decoratorOrName, cb) {
let decorator
if (decoratorOrName instanceof OperatorDecorator) {
decorator = decoratorOrName
} else {
decorator = new OperatorDecorator(decoratorOrName, cb)
}
debug('operatorMap::addOperatorDecorator', { name: decorator.name })
this.decor... | Add a custom operator decorator
@param {string} decoratorOrName - decorator identifier within the condition; i.e. instead of 'everyFact', 'someValue', etc
@param {function(factValue, jsonValue, next)} callback - the method to execute when the decorator is encountered. | addOperatorDecorator | javascript | CacheControl/json-rules-engine | src/operator-map.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/operator-map.js | ISC |
removeOperatorDecorator (decoratorOrName) {
let decoratorName
if (decoratorOrName instanceof OperatorDecorator) {
decoratorName = decoratorOrName.name
} else {
decoratorName = decoratorOrName
}
// Delete all the operators that include decoratorName: these
// were decorated on-the-fl... | Remove a custom operator decorator
@param {string} decoratorOrName - decorator identifier within the condition; i.e. instead of 'everyFact', 'someValue', etc | removeOperatorDecorator | javascript | CacheControl/json-rules-engine | src/operator-map.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/operator-map.js | ISC |
get (name) {
const decorators = []
let opName = name
// while we don't already have this operator
while (!this.operators.has(opName)) {
// try splitting on the decorator symbol (:)
const firstDecoratorIndex = opName.indexOf(':')
if (firstDecoratorIndex > 0) {
// if there is a d... | Get the Operator, or null applies decorators as needed
@param {string} name - the name of the operator including any decorators
@returns an operator or null | get | javascript | CacheControl/json-rules-engine | src/operator-map.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/operator-map.js | ISC |
constructor (name, cb, factValueValidator) {
this.name = String(name)
if (!name) throw new Error('Missing operator name')
if (typeof cb !== 'function') throw new Error('Missing operator callback')
this.cb = cb
this.factValueValidator = factValueValidator
if (!this.factValueValidator) this.factVa... | Constructor
@param {string} name - operator identifier
@param {function(factValue, jsonValue)} callback - operator evaluation method
@param {function} [factValueValidator] - optional validator for asserting the data type of the fact
@returns {Operator} - instance | constructor | javascript | CacheControl/json-rules-engine | src/operator.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/operator.js | ISC |
evaluate (factValue, jsonValue) {
return this.factValueValidator(factValue) && this.cb(factValue, jsonValue)
} | Takes the fact result and compares it to the condition 'value', using the callback
@param {mixed} factValue - fact result
@param {mixed} jsonValue - "value" property of the condition
@returns {Boolean} - whether the values pass the operator test | evaluate | javascript | CacheControl/json-rules-engine | src/operator.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/operator.js | ISC |
setPriority (priority) {
priority = parseInt(priority, 10)
if (priority <= 0) throw new Error('Priority must be greater than zero')
this.priority = priority
return this
} | Sets the priority of the rule
@param {integer} priority (>=1) - increasing the priority causes the rule to be run prior to other rules | setPriority | javascript | CacheControl/json-rules-engine | src/rule.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/rule.js | ISC |
setName (name) {
if (!name && name !== 0) {
throw new Error('Rule "name" must be defined')
}
this.name = name
return this
} | Sets the name of the rule
@param {any} name - any truthy input and zero is allowed | setName | javascript | CacheControl/json-rules-engine | src/rule.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/rule.js | ISC |
setConditions (conditions) {
if (
!Object.prototype.hasOwnProperty.call(conditions, 'all') &&
!Object.prototype.hasOwnProperty.call(conditions, 'any') &&
!Object.prototype.hasOwnProperty.call(conditions, 'not') &&
!Object.prototype.hasOwnProperty.call(conditions, 'condition')
) {
t... | Sets the conditions to run when evaluating the rule.
@param {object} conditions - conditions, root element must be a boolean operator | setConditions | javascript | CacheControl/json-rules-engine | src/rule.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/rule.js | ISC |
getEvent () {
return this.ruleEvent
} | returns the event object
@returns {Object} event | getEvent | javascript | CacheControl/json-rules-engine | src/rule.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/rule.js | ISC |
getPriority () {
return this.priority
} | returns the priority
@returns {Number} priority | getPriority | javascript | CacheControl/json-rules-engine | src/rule.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/rule.js | ISC |
getConditions () {
return this.conditions
} | returns the event object
@returns {Object} event | getConditions | javascript | CacheControl/json-rules-engine | src/rule.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/rule.js | ISC |
getEngine () {
return this.engine
} | returns the engine object
@returns {Object} engine | getEngine | javascript | CacheControl/json-rules-engine | src/rule.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/rule.js | ISC |
setEngine (engine) {
this.engine = engine
return this
} | Sets the engine to run the rules under
@param {object} engine
@returns {Rule} | setEngine | javascript | CacheControl/json-rules-engine | src/rule.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/rule.js | ISC |
toJSON (stringify = true) {
const props = {
conditions: this.conditions.toJSON(false),
priority: this.priority,
event: this.ruleEvent,
name: this.name
}
if (stringify) {
return JSON.stringify(props)
}
return props
} | Sets the engine to run the rules under
@param {object} engine
@returns {Rule} | toJSON | javascript | CacheControl/json-rules-engine | src/rule.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/rule.js | ISC |
prioritizeConditions (conditions) {
const factSets = conditions.reduce((sets, condition) => {
// if a priority has been set on this specific condition, honor that first
// otherwise, use the fact's priority
let priority = condition.priority
if (!priority) {
const fact = this.engine.g... | Priorizes an array of conditions based on "priority"
When no explicit priority is provided on the condition itself, the condition's priority is determine by its fact
@param {Condition[]} conditions
@return {Condition[][]} prioritized two-dimensional array of conditions
Each outer array element represents a single... | prioritizeConditions | javascript | CacheControl/json-rules-engine | src/rule.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/rule.js | ISC |
evaluate (almanac) {
const ruleResult = new RuleResult(
this.conditions,
this.ruleEvent,
this.priority,
this.name
)
/**
* Evaluates the rule conditions
* @param {Condition} condition - condition to evaluate
* @return {Promise(true|false)} - resolves with the result o... | Evaluates the rule, starting with the root boolean operator and recursing down
All evaluation is done within the context of an almanac
@return {Promise(RuleResult)} rule evaluation result | evaluate | javascript | CacheControl/json-rules-engine | src/rule.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/rule.js | ISC |
evaluateCondition = (condition) => {
if (condition.isConditionReference()) {
return realize(condition)
} else if (condition.isBooleanOperator()) {
const subConditions = condition[condition.operator]
let comparisonPromise
if (condition.operator === 'all') {
compariso... | Evaluates the rule conditions
@param {Condition} condition - condition to evaluate
@return {Promise(true|false)} - resolves with the result of the condition evaluation | evaluateCondition | javascript | CacheControl/json-rules-engine | src/rule.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/rule.js | ISC |
evaluateCondition = (condition) => {
if (condition.isConditionReference()) {
return realize(condition)
} else if (condition.isBooleanOperator()) {
const subConditions = condition[condition.operator]
let comparisonPromise
if (condition.operator === 'all') {
compariso... | Evaluates the rule conditions
@param {Condition} condition - condition to evaluate
@return {Promise(true|false)} - resolves with the result of the condition evaluation | evaluateCondition | javascript | CacheControl/json-rules-engine | src/rule.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/rule.js | ISC |
evaluateConditions = (conditions, method) => {
if (!Array.isArray(conditions)) conditions = [conditions]
return Promise.all(
conditions.map((condition) => evaluateCondition(condition))
).then((conditionResults) => {
debug('rule::evaluateConditions', { results: conditionResults })
... | Evalutes an array of conditions, using an 'every' or 'some' array operation
@param {Condition[]} conditions
@param {string(every|some)} array method to call for determining result
@return {Promise(boolean)} whether conditions evaluated truthy or falsey based on condition evaluation + method | evaluateConditions | javascript | CacheControl/json-rules-engine | src/rule.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/rule.js | ISC |
evaluateConditions = (conditions, method) => {
if (!Array.isArray(conditions)) conditions = [conditions]
return Promise.all(
conditions.map((condition) => evaluateCondition(condition))
).then((conditionResults) => {
debug('rule::evaluateConditions', { results: conditionResults })
... | Evalutes an array of conditions, using an 'every' or 'some' array operation
@param {Condition[]} conditions
@param {string(every|some)} array method to call for determining result
@return {Promise(boolean)} whether conditions evaluated truthy or falsey based on condition evaluation + method | evaluateConditions | javascript | CacheControl/json-rules-engine | src/rule.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/rule.js | ISC |
prioritizeAndRun = (conditions, operator) => {
if (conditions.length === 0) {
return Promise.resolve(true)
}
if (conditions.length === 1) {
// no prioritizing is necessary, just evaluate the single condition
// 'all' and 'any' will give the same results with a single condition ... | Evaluates a set of conditions based on an 'all', 'any', or 'not' operator.
First, orders the top level conditions based on priority
Iterates over each priority set, evaluating each condition
If any condition results in the rule to be guaranteed truthy or falsey,
it will short-circuit and not bother evaluating a... | prioritizeAndRun | javascript | CacheControl/json-rules-engine | src/rule.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/rule.js | ISC |
prioritizeAndRun = (conditions, operator) => {
if (conditions.length === 0) {
return Promise.resolve(true)
}
if (conditions.length === 1) {
// no prioritizing is necessary, just evaluate the single condition
// 'all' and 'any' will give the same results with a single condition ... | Evaluates a set of conditions based on an 'all', 'any', or 'not' operator.
First, orders the top level conditions based on priority
Iterates over each priority set, evaluating each condition
If any condition results in the rule to be guaranteed truthy or falsey,
it will short-circuit and not bother evaluating a... | prioritizeAndRun | javascript | CacheControl/json-rules-engine | src/rule.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/rule.js | ISC |
any = (conditions) => {
return prioritizeAndRun(conditions, 'any')
} | Runs an 'any' boolean operator on an array of conditions
@param {Condition[]} conditions to be evaluated
@return {Promise(boolean)} condition evaluation result | any | javascript | CacheControl/json-rules-engine | src/rule.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/rule.js | ISC |
any = (conditions) => {
return prioritizeAndRun(conditions, 'any')
} | Runs an 'any' boolean operator on an array of conditions
@param {Condition[]} conditions to be evaluated
@return {Promise(boolean)} condition evaluation result | any | javascript | CacheControl/json-rules-engine | src/rule.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/rule.js | ISC |
all = (conditions) => {
return prioritizeAndRun(conditions, 'all')
} | Runs an 'all' boolean operator on an array of conditions
@param {Condition[]} conditions to be evaluated
@return {Promise(boolean)} condition evaluation result | all | javascript | CacheControl/json-rules-engine | src/rule.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/rule.js | ISC |
all = (conditions) => {
return prioritizeAndRun(conditions, 'all')
} | Runs an 'all' boolean operator on an array of conditions
@param {Condition[]} conditions to be evaluated
@return {Promise(boolean)} condition evaluation result | all | javascript | CacheControl/json-rules-engine | src/rule.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/rule.js | ISC |
not = (condition) => {
return prioritizeAndRun([condition], 'not').then((result) => !result)
} | Runs a 'not' boolean operator on a single condition
@param {Condition} condition to be evaluated
@return {Promise(boolean)} condition evaluation result | not | javascript | CacheControl/json-rules-engine | src/rule.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/rule.js | ISC |
not = (condition) => {
return prioritizeAndRun([condition], 'not').then((result) => !result)
} | Runs a 'not' boolean operator on a single condition
@param {Condition} condition to be evaluated
@return {Promise(boolean)} condition evaluation result | not | javascript | CacheControl/json-rules-engine | src/rule.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/rule.js | ISC |
realize = (conditionReference) => {
const condition = this.engine.conditions.get(conditionReference.condition)
if (!condition) {
if (this.engine.allowUndefinedConditions) {
// undefined conditions always fail
conditionReference.result = false
return Promise.resolve(fals... | Dereferences the condition reference and then evaluates it.
@param {Condition} conditionReference
@returns {Promise(boolean)} condition evaluation result | realize | javascript | CacheControl/json-rules-engine | src/rule.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/rule.js | ISC |
realize = (conditionReference) => {
const condition = this.engine.conditions.get(conditionReference.condition)
if (!condition) {
if (this.engine.allowUndefinedConditions) {
// undefined conditions always fail
conditionReference.result = false
return Promise.resolve(fals... | Dereferences the condition reference and then evaluates it.
@param {Condition} conditionReference
@returns {Promise(boolean)} condition evaluation result | realize | javascript | CacheControl/json-rules-engine | src/rule.js | https://github.com/CacheControl/json-rules-engine/blob/master/src/rule.js | ISC |
function simpleSetup () {
const conditions = {
any: [
{
name: 'over 21',
fact: 'age',
operator: 'greaterThanInclusive',
value: 21
},
{
fact: 'qualified',
operator: 'equal',
value: true
}
]
}
eng... | sets up a simple 'any' rule with 2 conditions | simpleSetup | javascript | CacheControl/json-rules-engine | test/engine-event.test.js | https://github.com/CacheControl/json-rules-engine/blob/master/test/engine-event.test.js | ISC |
function advancedSetup () {
const conditions = {
any: [
{
fact: 'age',
operator: 'greaterThanInclusive',
value: 21
},
{
fact: 'qualified',
operator: 'equal',
value: true
},
{
all: [
{
... | sets up a complex rule with nested conditions | advancedSetup | javascript | CacheControl/json-rules-engine | test/engine-event.test.js | https://github.com/CacheControl/json-rules-engine/blob/master/test/engine-event.test.js | ISC |
function setupWithConditionReference () {
const conditionName = 'awesomeCondition'
const conditions = {
any: [{ condition: conditionName }]
}
engine = engineFactory()
const ruleOptions = { conditions, event: awesomeEvent, priority: 100 }
const rule = factories.rule(ruleOptions)
engine.... | sets up a complex rule with nested conditions | setupWithConditionReference | javascript | CacheControl/json-rules-engine | test/engine-event.test.js | https://github.com/CacheControl/json-rules-engine/blob/master/test/engine-event.test.js | ISC |
function setupWithUndefinedCondition () {
const conditionName = 'conditionThatIsNotDefined'
const conditions = {
any: [
{ condition: conditionName, name: 'nameOfTheUndefinedConditionReference' },
{
name: 'over 21',
fact: 'age',
operator: 'greaterThanInclusive'... | sets up a complex rule with nested conditions | setupWithUndefinedCondition | javascript | CacheControl/json-rules-engine | test/engine-event.test.js | https://github.com/CacheControl/json-rules-engine/blob/master/test/engine-event.test.js | ISC |
function assertResult (ruleResult) {
expect(ruleResult.result).to.be.true()
expect(ruleResult.conditions.any[0].result).to.be.true()
expect(ruleResult.conditions.any[0].factResult).to.equal(21)
expect(ruleResult.conditions.any[0].name).to.equal('over 21')
expect(ruleResult.condit... | sets up a complex rule with nested conditions | assertResult | javascript | CacheControl/json-rules-engine | test/engine-event.test.js | https://github.com/CacheControl/json-rules-engine/blob/master/test/engine-event.test.js | ISC |
function assertResult (ruleResult) {
expect(ruleResult.result).to.be.true()
expect(ruleResult.conditions.any[0].result).to.be.true()
expect(ruleResult.conditions.any[0].factResult).to.equal(21)
expect(ruleResult.conditions.any[1].result).to.be.false()
expect(ruleResult.conditions... | sets up a complex rule with nested conditions | assertResult | javascript | CacheControl/json-rules-engine | test/engine-event.test.js | https://github.com/CacheControl/json-rules-engine/blob/master/test/engine-event.test.js | ISC |
function assertResult (ruleResult) {
expect(ruleResult.result).to.be.false()
expect(ruleResult.conditions.any[0].result).to.be.false()
expect(ruleResult.conditions.any[0].factResult).to.equal(AGE)
expect(ruleResult.conditions.any[1].result).to.be.false()
expect(ruleResult.conditi... | sets up a complex rule with nested conditions | assertResult | javascript | CacheControl/json-rules-engine | test/engine-event.test.js | https://github.com/CacheControl/json-rules-engine/blob/master/test/engine-event.test.js | ISC |
function assertResult (ruleResult) {
expect(ruleResult.result).to.be.true()
expect(ruleResult.conditions.any[0].result).to.be.false()
expect(ruleResult.conditions.any[0].factResult).to.equal(10)
expect(ruleResult.conditions.any[1].result).to.be.false()
expect(ruleResult.condition... | sets up a complex rule with nested conditions | assertResult | javascript | CacheControl/json-rules-engine | test/engine-event.test.js | https://github.com/CacheControl/json-rules-engine/blob/master/test/engine-event.test.js | ISC |
function assertResult (ruleResult) {
expect(ruleResult.result).to.be.false()
expect(ruleResult.conditions.any[0].result).to.be.false()
expect(ruleResult.conditions.any[0].factResult).to.equal(10)
expect(ruleResult.conditions.any[1].result).to.be.false()
expect(ruleResult.conditio... | sets up a complex rule with nested conditions | assertResult | javascript | CacheControl/json-rules-engine | test/engine-event.test.js | https://github.com/CacheControl/json-rules-engine/blob/master/test/engine-event.test.js | ISC |
function setup (replaceFactsInEventParams, event = eventWithFact) {
const conditions = {
any: [
{
fact: 'success',
operator: 'equal',
value: true
}
]
}
const ruleOptions = { conditions, event, priority: 100 }
const countedE... | sets up a complex rule with nested conditions | setup | javascript | CacheControl/json-rules-engine | test/engine-event.test.js | https://github.com/CacheControl/json-rules-engine/blob/master/test/engine-event.test.js | ISC |
function assertResult (ruleResult) {
expect(ruleResult.result).to.be.true()
expect(ruleResult.conditions.any[0].result).to.be.true()
expect(ruleResult.conditions.any[0].factResult).to.equal(21)
expect(ruleResult.conditions.any[1].result).to.be.false()
expect(ruleResult.conditions... | sets up a complex rule with nested conditions | assertResult | javascript | CacheControl/json-rules-engine | test/engine-event.test.js | https://github.com/CacheControl/json-rules-engine/blob/master/test/engine-event.test.js | ISC |
function assertResult (ruleResult) {
expect(ruleResult.result).to.be.false()
expect(ruleResult.conditions.any[0].result).to.be.false()
expect(ruleResult.conditions.any[0].factResult).to.equal(AGE)
expect(ruleResult.conditions.any[1].result).to.be.false()
expect(ruleResult.conditi... | sets up a complex rule with nested conditions | assertResult | javascript | CacheControl/json-rules-engine | test/engine-event.test.js | https://github.com/CacheControl/json-rules-engine/blob/master/test/engine-event.test.js | ISC |
function setup (replaceFactsInEventParams, event = eventWithFact) {
const conditions = {
any: [
{
fact: 'success',
operator: 'equal',
value: true
}
]
}
const ruleOptions = { conditions, event, priority: 100 }
const countedE... | sets up a complex rule with nested conditions | setup | javascript | CacheControl/json-rules-engine | test/engine-event.test.js | https://github.com/CacheControl/json-rules-engine/blob/master/test/engine-event.test.js | ISC |
function delay (value) {
return new Promise(resolve => setTimeout(() => resolve(value), 5))
} | acceptance tests are intended to use features that, when used in combination,
could cause integration bugs not caught by the rest of the test suite | delay | javascript | CacheControl/json-rules-engine | test/acceptance/acceptance.js | https://github.com/CacheControl/json-rules-engine/blob/master/test/acceptance/acceptance.js | ISC |
function setup (options = {}) {
const engine = new Engine()
highPrioritySpy = sandbox.spy()
lowPrioritySpy = sandbox.spy()
engine.addRule({
name: 'first',
priority: 10,
conditions: {
all: [{
fact: 'high-priority',
params: {
factParam
}... | acceptance tests are intended to use features that, when used in combination,
could cause integration bugs not caught by the rest of the test suite | setup | javascript | CacheControl/json-rules-engine | test/acceptance/acceptance.js | https://github.com/CacheControl/json-rules-engine/blob/master/test/acceptance/acceptance.js | ISC |
function capitalize (str) {
return str.charAt(0).toUpperCase() + str.slice(1)
} | Register a custom event.
@param {String} event
@param {Object} options - a Hammer.js recognizer option object.
required fields:
- type: the base recognizer to use for this event | capitalize | javascript | vuejs/vue-touch | vue-touch.js | https://github.com/vuejs/vue-touch/blob/master/vue-touch.js | MIT |
function guardDirections (options) {
var dir = options.direction
if (typeof dir === 'string') {
var hammerDirection = 'DIRECTION_' + dir.toUpperCase()
if (directions.indexOf(dir) > -1 && Hammer.hasOwnProperty(hammerDirection)) {
options.direction = Hammer[hammerDirection]
} else {
... | Register a custom event.
@param {String} event
@param {Object} options - a Hammer.js recognizer option object.
required fields:
- type: the base recognizer to use for this event | guardDirections | javascript | vuejs/vue-touch | vue-touch.js | https://github.com/vuejs/vue-touch/blob/master/vue-touch.js | MIT |
constructor(el, location) {
const hash = location.hash ? queryString.parse(location.hash) : {};
this.options = {
kiosk: Boolean(hash.kiosk),
model: hash.model || '',
preset: hash.preset || '',
cameraPosition: hash.cameraPosition ? hash.cameraPosition.split(',').map(Number) : null,
};
this.el = el;
... | @param {Element} el
@param {Location} location | constructor | javascript | donmccurdy/three-gltf-viewer | src/app.js | https://github.com/donmccurdy/three-gltf-viewer/blob/master/src/app.js | MIT |
createDropzone() {
const dropCtrl = new SimpleDropzone(this.dropEl, this.inputEl);
dropCtrl.on('drop', ({ files }) => this.load(files));
dropCtrl.on('dropstart', () => this.showSpinner());
dropCtrl.on('droperror', () => this.hideSpinner());
} | Sets up the drag-and-drop controller. | createDropzone | javascript | donmccurdy/three-gltf-viewer | src/app.js | https://github.com/donmccurdy/three-gltf-viewer/blob/master/src/app.js | MIT |
createViewer() {
this.viewerEl = document.createElement('div');
this.viewerEl.classList.add('viewer');
this.dropEl.innerHTML = '';
this.dropEl.appendChild(this.viewerEl);
this.viewer = new Viewer(this.viewerEl, this.options);
return this.viewer;
} | Sets up the view manager.
@return {Viewer} | createViewer | javascript | donmccurdy/three-gltf-viewer | src/app.js | https://github.com/donmccurdy/three-gltf-viewer/blob/master/src/app.js | MIT |
load(fileMap) {
let rootFile;
let rootPath;
Array.from(fileMap).forEach(([path, file]) => {
if (file.name.match(/\.(gltf|glb)$/)) {
rootFile = file;
rootPath = path.replace(file.name, '');
}
});
if (!rootFile) {
this.onError('No .gltf or .glb asset found.');
}
this.view(rootFile, rootPa... | Loads a fileset provided by user action.
@param {Map<string, File>} fileMap | load | javascript | donmccurdy/three-gltf-viewer | src/app.js | https://github.com/donmccurdy/three-gltf-viewer/blob/master/src/app.js | MIT |
view(rootFile, rootPath, fileMap) {
if (this.viewer) this.viewer.clear();
const viewer = this.viewer || this.createViewer();
const fileURL = typeof rootFile === 'string' ? rootFile : URL.createObjectURL(rootFile);
const cleanup = () => {
this.hideSpinner();
if (typeof rootFile === 'object') URL.revokeO... | Passes a model to the viewer, given file and resources.
@param {File|string} rootFile
@param {string} rootPath
@param {Map<string, File>} fileMap | view | javascript | donmccurdy/three-gltf-viewer | src/app.js | https://github.com/donmccurdy/three-gltf-viewer/blob/master/src/app.js | MIT |
cleanup = () => {
this.hideSpinner();
if (typeof rootFile === 'object') URL.revokeObjectURL(fileURL);
} | Passes a model to the viewer, given file and resources.
@param {File|string} rootFile
@param {string} rootPath
@param {Map<string, File>} fileMap | cleanup | javascript | donmccurdy/three-gltf-viewer | src/app.js | https://github.com/donmccurdy/three-gltf-viewer/blob/master/src/app.js | MIT |
cleanup = () => {
this.hideSpinner();
if (typeof rootFile === 'object') URL.revokeObjectURL(fileURL);
} | Passes a model to the viewer, given file and resources.
@param {File|string} rootFile
@param {string} rootPath
@param {Map<string, File>} fileMap | cleanup | javascript | donmccurdy/three-gltf-viewer | src/app.js | https://github.com/donmccurdy/three-gltf-viewer/blob/master/src/app.js | MIT |
validate(rootFile, rootPath, assetMap, response) {
// TODO: This duplicates a request of the three.js loader, and could
// take advantage of THREE.Cache after r90.
return fetch(rootFile)
.then((response) => response.arrayBuffer())
.then((buffer) =>
validateBytes(new Uint8Array(buffer), {
externalRe... | Runs validation against the given file URL and extra resources.
@param {string} rootFile
@param {string} rootPath
@param {Map<string, File>} assetMap
@param {Object} response
@return {Promise} | validate | javascript | donmccurdy/three-gltf-viewer | src/validator.js | https://github.com/donmccurdy/three-gltf-viewer/blob/master/src/validator.js | MIT |
resolveExternalResource(uri, rootFile, rootPath, assetMap) {
const baseURL = LoaderUtils.extractUrlBase(rootFile);
const normalizedURL =
rootPath +
decodeURI(uri) // validator applies URI encoding.
.replace(baseURL, '')
.replace(/^(\.?\/)/, '');
let objectURL;
if (assetMap.has(normalizedURL)) {
... | Loads a resource (either locally or from the network) and returns it.
@param {string} uri
@param {string} rootFile
@param {string} rootPath
@param {Map<string, File>} assetMap
@return {Promise<Uint8Array>} | resolveExternalResource | javascript | donmccurdy/three-gltf-viewer | src/validator.js | https://github.com/donmccurdy/three-gltf-viewer/blob/master/src/validator.js | MIT |
setReport(report, response) {
report.generator = (report && report.info && report.info.generator) || '';
report.issues.maxSeverity = -1;
SEVERITY_MAP.forEach((severity, index) => {
if (report.issues[`num${severity}`] > 0 && report.issues.maxSeverity === -1) {
report.issues.maxSeverity = index;
}
});
... | @param {GLTFValidator.Report} report
@param {Object} response | setReport | javascript | donmccurdy/three-gltf-viewer | src/validator.js | https://github.com/donmccurdy/three-gltf-viewer/blob/master/src/validator.js | MIT |
function groupMessages(report) {
const CODES = {
ACCESSOR_NON_UNIT: {
message: '{count} accessor elements not of unit length: 0. [AGGREGATED]',
pointerCounts: {},
},
ACCESSOR_ANIMATION_INPUT_NON_INCREASING: {
message:
'{count} animation input accessor elements not in ascending order.... | @param {GLTFValidator.Report} report
@param {Object} response | groupMessages | javascript | donmccurdy/three-gltf-viewer | src/validator.js | https://github.com/donmccurdy/three-gltf-viewer/blob/master/src/validator.js | MIT |
setContent(object, clips) {
this.clear();
object.updateMatrixWorld(); // donmccurdy/three-gltf-viewer#330
const box = new Box3().setFromObject(object);
const size = box.getSize(new Vector3()).length();
const center = box.getCenter(new Vector3());
this.controls.reset();
object.position.x -= center.x;
... | @param {THREE.Object3D} object
@param {Array<THREE.AnimationClip} clips | setContent | javascript | donmccurdy/three-gltf-viewer | src/viewer.js | https://github.com/donmccurdy/three-gltf-viewer/blob/master/src/viewer.js | MIT |
printGraph(node) {
console.group(' <' + node.type + '> ' + node.name);
node.children.forEach((child) => this.printGraph(child));
console.groupEnd();
} | @param {THREE.Object3D} object
@param {Array<THREE.AnimationClip} clips | printGraph | javascript | donmccurdy/three-gltf-viewer | src/viewer.js | https://github.com/donmccurdy/three-gltf-viewer/blob/master/src/viewer.js | MIT |
addAxesHelper() {
this.axesDiv = document.createElement('div');
this.el.appendChild(this.axesDiv);
this.axesDiv.classList.add('axes');
const { clientWidth, clientHeight } = this.axesDiv;
this.axesScene = new Scene();
this.axesCamera = new PerspectiveCamera(50, clientWidth / clientHeight, 0.1, 10);
this.... | Adds AxesHelper.
See: https://stackoverflow.com/q/16226693/1314762 | addAxesHelper | javascript | donmccurdy/three-gltf-viewer | src/viewer.js | https://github.com/donmccurdy/three-gltf-viewer/blob/master/src/viewer.js | MIT |
addGUI() {
const gui = (this.gui = new GUI({
autoPlace: false,
width: 260,
hideable: true,
}));
// Display controls.
const dispFolder = gui.addFolder('Display');
const envBackgroundCtrl = dispFolder.add(this.state, 'background');
envBackgroundCtrl.onChange(() => this.updateEnvironment());
const ... | Adds AxesHelper.
See: https://stackoverflow.com/q/16226693/1314762 | addGUI | javascript | donmccurdy/three-gltf-viewer | src/viewer.js | https://github.com/donmccurdy/three-gltf-viewer/blob/master/src/viewer.js | MIT |
updateGUI() {
this.cameraFolder.domElement.style.display = 'none';
this.morphCtrls.forEach((ctrl) => ctrl.remove());
this.morphCtrls.length = 0;
this.morphFolder.domElement.style.display = 'none';
this.animCtrls.forEach((ctrl) => ctrl.remove());
this.animCtrls.length = 0;
this.animFolder.domElement.styl... | Adds AxesHelper.
See: https://stackoverflow.com/q/16226693/1314762 | updateGUI | javascript | donmccurdy/three-gltf-viewer | src/viewer.js | https://github.com/donmccurdy/three-gltf-viewer/blob/master/src/viewer.js | MIT |
clear() {
if (!this.content) return;
this.scene.remove(this.content);
// dispose geometry
this.content.traverse((node) => {
if (!node.geometry) return;
node.geometry.dispose();
});
// dispose textures
traverseMaterials(this.content, (material) => {
for (const key in material) {
if (key !=... | Adds AxesHelper.
See: https://stackoverflow.com/q/16226693/1314762 | clear | javascript | donmccurdy/three-gltf-viewer | src/viewer.js | https://github.com/donmccurdy/three-gltf-viewer/blob/master/src/viewer.js | MIT |
function traverseMaterials(object, callback) {
object.traverse((node) => {
if (!node.geometry) return;
const materials = Array.isArray(node.material) ? node.material : [node.material];
materials.forEach(callback);
});
} | Adds AxesHelper.
See: https://stackoverflow.com/q/16226693/1314762 | traverseMaterials | javascript | donmccurdy/three-gltf-viewer | src/viewer.js | https://github.com/donmccurdy/three-gltf-viewer/blob/master/src/viewer.js | MIT |
function isIOS() {
return (
['iPad Simulator', 'iPhone Simulator', 'iPod Simulator', 'iPad', 'iPhone', 'iPod'].includes(
navigator.platform,
) ||
// iPad on iOS 13 detection
(navigator.userAgent.includes('Mac') && 'ontouchend' in document)
);
} | Adds AxesHelper.
See: https://stackoverflow.com/q/16226693/1314762 | isIOS | javascript | donmccurdy/three-gltf-viewer | src/viewer.js | https://github.com/donmccurdy/three-gltf-viewer/blob/master/src/viewer.js | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.