charting refactor into shapes, not debugged

This commit is contained in:
Tim
2024-02-05 20:02:49 -04:00
parent 5587915728
commit 042f96b37c
13 changed files with 614 additions and 114 deletions

44
src/common.js Normal file
View File

@@ -0,0 +1,44 @@
export function mixin(child, ...parents) {
// child is modified directly, assigning fields from parents that are missing in child. parents fields are
// assigned by parents order, highest priority first
for( const parent of parents ) {
for ( const key in parent) {
if (parent.hasOwnProperty(key) && !child.hasOwnProperty(key)) {
child[key] = parent[key];
}
}
}
return child;
}
export function prototype(parent, child) {
const result = Object.create(parent);
Object.assign(result, child)
return result
}
export function invokeCallback(cbs, prop, ...args) {
if (prop in cbs) cbs[prop].call(cbs, ...args)
}
export function invokeCallbacks(callbacks, prop, ...args) {
if (!callbacks) return
callbacks.forEach((cb)=>invokeCallback(cb, prop, ...args))
}
export function encodeIEE754(value) {
const buffer = new ArrayBuffer(4);
const view = new DataView(buffer);
view.setFloat32(0, value, false /* big endian */);
return view.getUint32(0, false);
}
export function decodeIEE754(value) {
const buffer = new ArrayBuffer(4);
const view = new DataView(buffer);
view.setUint32(0, value, false)
return view.getFloat32(0, false)
}