This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![allow(unused_variables)] | |
fn main() { | |
use wasm_bindgen::prelude::*; | |
// Called by our JS entry point to run the example | |
#[wasm_bindgen(start)] | |
pub fn rust_in_peace() -> Result<(), JsValue> { | |
// Use `web_sys`'s global `window` function to get a handle on the global | |
// window object. | |
let window = web_sys::window().expect("no global `window` exists"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class updateEditorExample { | |
private queryEditorState: Readonly<QueryEditorState>; | |
static updateEditorState (editorState: Readonly<QueryEditorState>, sliceToUpdate: Partial<Readonly<QueryEditorState>>) { | |
return { ...editorState, ...sliceToUpdate }; | |
} | |
// Get new state: | |
doSomthingGood(newText: string) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FunWithFunctionalTS { | |
queryEditorState: Readonly<QueryEditorState>; | |
static updateEditorState( | |
editorState: Readonly<QueryEditorState>, | |
sliceToUpdate: Partial<Readonly<QueryEditorState>> | |
): Readonly<QueryEditorState> { | |
return { ...editorState, ...sliceToUpdate }; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'reflect-metadata'; | |
import {Ctr} from "../../../common/types"; | |
export class Injector { | |
private depInstances: Map<string, Ctr<any>> = new Map<string, Ctr<any>>(); | |
// Not storing an instances map | |
static resolve<T>(target: Ctr<any>): T { | |
const tokens = Reflect.getMetadata('design:paramtypes', target) || []; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Ctr} from "../../../common/types"; | |
type ClazzDecorator<T> = (target: T) => void; | |
export const Injectable = () : ClazzDecorator<Ctr<any>> => { | |
return (target: Ctr<any>) => { | |
// this is needed so the design:paramtypes could be collected | |
console.log('inside: Injectable decorator'); | |
console.log(target.name, ' is used'); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Injector, Resolver} from "../src/diy/injector"; | |
import {RendererService} from "./services/renderer.service"; | |
class DiBootstrap { | |
static run() { | |
console.log('---------------- | START | -----------------'); | |
// Static injector |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function renderImage(ctx, url, width, height): Promise<boolean> { | |
return new Promise((resolve) => { | |
fetch(url) | |
.then((res) => res.blob()) | |
.then((blob) => createImageBitmap(blob)) | |
.then((ibm) => { | |
ctx.drawImage(ibm, 0, 0); | |
resolve(); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {BehaviorSubject, Observable} from 'rxjs'; | |
export class StoreService<T> { | |
private readonly state$: BehaviorSubject<T>; | |
protected get state(): T { | |
return this.state$.getValue(); | |
} | |
constructor(initialState: T) { | |
this.state$ = new BehaviorSubject<T>(initialState); | |
} | |
protected getState(): Observable<T> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private unsubscribeDataFetch: Subject<void> = new Subject<void>(); | |
// polling data till we get what we need and stop | |
fetchData() { | |
this.dataService | |
.pipe(takeUntil(this.unsubscribeDataFetch)) | |
.subscribe((data) => actOnData(data)); | |
} | |
actOnData(data) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
registerTransitionEnd<T extends {propertyName}>(el: FromEventTarget<T>, propName: string) { | |
// Returns an Observable from DOM event | |
fromEvent(el, 'transitionend') | |
.pipe( | |
filter(({ propertyName }: T) => propertyName === propName) // Will only emit value for the wanted css prop name e.g. height | |
) | |
.subscribe((_) => { | |
this.transitionEnd.emit(); | |
}); | |
} |