superfly-timeline
Advanced tools
Comparing version 8.2.3-nightly-20211109-110847-c7f28e5.0 to 8.2.3-nightly-20220104-092548-08ab807.0
@@ -65,3 +65,4 @@ import { InstanceEvent, TimelineObjectInstance, ResolveOptions, ValueWithReference, Cap } from './api/api'; | ||
export declare function cacheResult<T>(name: string, fcn: () => T, limitTime?: number): T; | ||
export declare function cleanCacheResult(): void; | ||
export {}; | ||
//# sourceMappingURL=lib.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.cacheResult = exports.applyParentInstances = exports.setInstanceStartTime = exports.setInstanceEndTime = exports.resetId = exports.getId = exports.joinCaps = exports.addCapsToResuming = exports.joinReferences = exports.isReference = exports.capInstances = exports.applyRepeatingInstances = exports.operateOnArrays = exports.invertInstances = exports.convertEventsToInstances = exports.cleanInstances = exports.sortEvents = exports.isNumeric = exports.isConstant = exports.extendMandadory = void 0; | ||
exports.cleanCacheResult = exports.cacheResult = exports.applyParentInstances = exports.setInstanceStartTime = exports.setInstanceEndTime = exports.resetId = exports.getId = exports.joinCaps = exports.addCapsToResuming = exports.joinReferences = exports.isReference = exports.capInstances = exports.applyRepeatingInstances = exports.operateOnArrays = exports.invertInstances = exports.convertEventsToInstances = exports.cleanInstances = exports.sortEvents = exports.isNumeric = exports.isConstant = exports.extendMandadory = void 0; | ||
const _ = require("underscore"); | ||
@@ -528,18 +528,23 @@ /** | ||
function applyParentInstances(parentInstances, value) { | ||
const operate = (a, b) => { | ||
if (a === null || b === null) | ||
return null; | ||
return { | ||
value: a.value + b.value, | ||
references: joinReferences(a.references, b.references), | ||
}; | ||
}; | ||
return operateOnArrays(parentInstances, value, operate); | ||
} | ||
exports.applyParentInstances = applyParentInstances; | ||
function operate(a, b) { | ||
if (a === null || b === null) | ||
return null; | ||
return { | ||
value: a.value + b.value, | ||
references: joinReferences(a.references, b.references), | ||
}; | ||
} | ||
const cacheResultCache = {}; | ||
let cleanCacheResultTimeout = null; | ||
/** Cache the result of function for a limited time */ | ||
function cacheResult(name, fcn, limitTime = 1000) { | ||
if (Math.random() < 0.01) { | ||
setTimeout(cleanCacheResult, 100); | ||
if (cleanCacheResultTimeout) | ||
clearTimeout(cleanCacheResultTimeout); | ||
cleanCacheResultTimeout = setTimeout(() => { | ||
cleanCacheResult(); | ||
}, 100); | ||
} | ||
@@ -561,2 +566,6 @@ const cache = cacheResultCache[name]; | ||
function cleanCacheResult() { | ||
if (cleanCacheResultTimeout) { | ||
clearTimeout(cleanCacheResultTimeout); | ||
cleanCacheResultTimeout = null; | ||
} | ||
_.each(cacheResultCache, (cache, name) => { | ||
@@ -567,2 +576,3 @@ if (cache.ttl < Date.now()) | ||
} | ||
exports.cleanCacheResult = cleanCacheResult; | ||
//# sourceMappingURL=lib.js.map |
@@ -107,3 +107,3 @@ "use strict"; | ||
}; | ||
_.each(resolvedTimeline.objects, (obj) => { | ||
for (const obj of Object.values(resolvedTimeline.objects)) { | ||
const oldHash = cache.objHashes[obj.id]; | ||
@@ -129,3 +129,3 @@ const newHash = cache_1.hashTimelineObject(obj); | ||
} | ||
}); | ||
} | ||
if (cache.hasOldData) { | ||
@@ -143,8 +143,8 @@ // Go through all old hashes, removing the ones that doesn't exist anymore | ||
const validObjects = {}; | ||
_.each(resolvedTimeline.objects, (obj) => { | ||
for (const obj of Object.values(resolvedTimeline.objects)) { | ||
validObjects[obj.id] = obj; | ||
}); | ||
} | ||
/** All references that depend on another reference (ie objects, classs or layers): */ | ||
const affectReferenceMap = {}; | ||
_.each(resolvedTimeline.objects, (obj) => { | ||
for (const obj of Object.values(resolvedTimeline.objects)) { | ||
// Add everything that this object affects: | ||
@@ -186,3 +186,3 @@ const cachedObj = cache.resolvedTimeline.objects[obj.id]; | ||
} | ||
}); | ||
} | ||
// Invalidate all changed objects, and recursively invalidate all objects that reference those objects: | ||
@@ -195,11 +195,11 @@ const handledReferences = {}; | ||
// We can reuse the old resolving for those: | ||
_.each(validObjects, (obj) => { | ||
for (const obj of Object.values(validObjects)) { | ||
if (!cache.resolvedTimeline.objects[obj.id]) | ||
throw new Error(`Something went wrong: "${obj.id}" does not exist in cache.resolvedTimeline.objects`); | ||
resolvedTimeline.objects[obj.id] = cache.resolvedTimeline.objects[obj.id]; | ||
}); | ||
} | ||
} | ||
_.each(resolvedTimeline.objects, (obj) => { | ||
for (const obj of Object.values(resolvedTimeline.objects)) { | ||
resolveTimelineObj(resolvedTimeline, obj); | ||
}); | ||
} | ||
// Save for next time: | ||
@@ -215,5 +215,5 @@ cache.resolvedTimeline = resolvedTimeline; | ||
resolvedTimeline.statistics.resolvedKeyframeCount = 0; | ||
_.each(resolvedTimeline.objects, (obj) => { | ||
for (const obj of Object.values(resolvedTimeline.objects)) { | ||
updateStatistics(resolvedTimeline, obj); | ||
}); | ||
} | ||
return resolvedTimeline; | ||
@@ -223,5 +223,5 @@ } | ||
// If there are no cache provided, just resolve all objects: | ||
_.each(resolvedTimeline.objects, (obj) => { | ||
for (const obj of Object.values(resolvedTimeline.objects)) { | ||
resolveTimelineObj(resolvedTimeline, obj); | ||
}); | ||
} | ||
return resolvedTimeline; | ||
@@ -228,0 +228,0 @@ } |
@@ -461,3 +461,3 @@ "use strict"; | ||
function applyKeyframeContent(parentContent, keyframeContent) { | ||
_.each(keyframeContent, (value, attr) => { | ||
for (const [attr, value] of Object.entries(keyframeContent)) { | ||
if (_.isArray(value)) { | ||
@@ -477,3 +477,3 @@ if (!_.isArray(parentContent[attr])) | ||
} | ||
}); | ||
} | ||
} | ||
@@ -480,0 +480,0 @@ exports.applyKeyframeContent = applyKeyframeContent; |
{ | ||
"name": "superfly-timeline", | ||
"version": "8.2.3-nightly-20211109-110847-c7f28e5.0", | ||
"version": "8.2.3-nightly-20220104-092548-08ab807.0", | ||
"description": "A collection of rules as well as a resolver for placing objects on a virtual timeline.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
296027
2825