mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-13 09:17:20 +00:00
Lazy-loading the main part of the app (#197)
* Splitting main part of app out of the main bundle. Also improving the transition from intro to compressor. * Showing error if app fails to load. * lol these aren't async * Please don't tell anyone I did this * Spinner if user selects a file before the app has loaded. (#208)
This commit is contained in:
@@ -1,30 +1,3 @@
|
||||
/**
|
||||
* A decorator that binds values to their class instance.
|
||||
* @example
|
||||
* class C {
|
||||
* @bind
|
||||
* foo () {
|
||||
* return this;
|
||||
* }
|
||||
* }
|
||||
* let f = new C().foo;
|
||||
* f() instanceof C; // true
|
||||
*/
|
||||
export function bind(target: any, propertyKey: string, descriptor: PropertyDescriptor) {
|
||||
return {
|
||||
// the first time the prototype property is accessed for an instance,
|
||||
// define an instance property pointing to the bound function.
|
||||
// This effectively "caches" the bound prototype method as an instance property.
|
||||
get() {
|
||||
const bound = descriptor.value.bind(this);
|
||||
Object.defineProperty(this, propertyKey, {
|
||||
value: bound,
|
||||
});
|
||||
return bound;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** Compare two objects, returning a boolean indicating if
|
||||
* they have the same properties and strictly equal values.
|
||||
*/
|
||||
@@ -34,22 +7,6 @@ export function shallowEqual(one: any, two: any) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Creates a function ref that assigns its value to a given property of an object.
|
||||
* @example
|
||||
* // element is stored as `this.foo` when rendered.
|
||||
* <div ref={linkRef(this, 'foo')} />
|
||||
*/
|
||||
export function linkRef<T>(obj: any, name: string) {
|
||||
const refName = `$$ref_${name}`;
|
||||
let ref = obj[refName];
|
||||
if (!ref) {
|
||||
ref = obj[refName] = (c: T) => {
|
||||
obj[name] = c;
|
||||
};
|
||||
}
|
||||
return ref;
|
||||
}
|
||||
|
||||
/** Replace the contents of a canvas with the given data */
|
||||
export function drawDataToCanvas(canvas: HTMLCanvasElement, data: ImageData) {
|
||||
const ctx = canvas.getContext('2d');
|
||||
@@ -263,11 +220,3 @@ export function konami(): Promise<void> {
|
||||
window.addEventListener('keydown', listener);
|
||||
});
|
||||
}
|
||||
|
||||
// Edge doesn't support `new File`, so here's a hacky alternative.
|
||||
// https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/9551546/
|
||||
export class Fileish extends Blob {
|
||||
constructor(data: any[], public name: string, opts?: BlobPropertyBag) {
|
||||
super(data, opts);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user