<commit_before>import { Emitter } from "../../Utils/emitter";
import { IDestroyable } from "../../Utils/utils.types";

export class ObservableScopeValue<T> {
    public get Value() {
        return ObservableScope.Value(this.scope);
    }

    constructor(protected scope: IObservableScope<T>) { }
}

export class ObservableScopeWrapper<T> extends ObservableScopeValue<T> implements IDestroyable {
    private scopeEmitter: Emitter;

    constructor(scope: IObservableScope<T>) { 
        super(scope);
        if(scope.emitter) {
            this.scopeEmitter = Emitter.Create();
            Emitter.On(scope.emitter, () => Emitter.Emit(this.scopeEmitter, this));
        }
    }

    public Scope<O>(callback: {(parent: T): O}): ObservableScope<O> {
        return new ObservableScope<O>(() => callback(this.Value));
    }

    public Watch(callback: {(scope: ObservableScopeValue<T>): void}) {
        if(!this.scopeEmitter)
            return;

        Emitter.On(this.scopeEmitter, callback);
    }

    public Unwatch(callback: {(scope: ObservableScopeValue<T>): void}) {
        if(!this.scopeEmitter)
            return;

        Emitter.Remove(this.scopeEmitter, callback);
    }

    public Destroy() {
        DestroyScope(this.scope);
        this.scopeEmitter && this.scopeEmitter.clear();
    }
}

export class ObservableScope<T> extends ObservableScopeWrapper<T> {
    constructor(getFunction: T | {(): T | Promise<T>}) {<commit_msg>watch is now fired immediately<commit_after>import { Emitter } from "../../Utils/emitter";
import { IDestroyable } from "../../Utils/utils.types";

export class ObservableScopeValue<T> {
    public get Value() {
        return ObservableScope.Value(this.scope);
    }

    constructor(protected scope: IObservableScope<T>) { }
}

export class ObservableScopeWrapper<T> extends ObservableScopeValue<T> implements IDestroyable {
    private scopeEmitter: Emitter;

    constructor(scope: IObservableScope<T>) { 
        super(scope);
        if(scope.emitter) {
            this.scopeEmitter = Emitter.Create();
            Emitter.On(scope.emitter, () => Emitter.Emit(this.scopeEmitter, this));
        }
    }

    public Scope<O>(callback: {(parent: T): O}): ObservableScope<O> {
        return new ObservableScope<O>(() => callback(this.Value));
    }

    public Watch(callback: {(scope: ObservableScopeValue<T>): void}) {
        if(!this.scopeEmitter)
            return;

        Emitter.On(this.scopeEmitter, callback);
        callback(this);
    }

    public Unwatch(callback: {(scope: ObservableScopeValue<T>): void}) {
        if(!this.scopeEmitter)
            return;

        Emitter.Remove(this.scopeEmitter, callback);
    }

    public Destroy() {
        DestroyScope(this.scope);
        this.scopeEmitter && this.scopeEmitter.clear();
    }
}

export class ObservableScope<T> extends ObservableScopeWrapper<T> {
    constructor(getFunction: T | {(): T | Promise<T>}) {
{'fraction_non_alphanumeric': 0.13857677902621723, 'fraction_numerical': 0.0, 'mean_word_length': 3.046831955922865, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7200595', 'n_tokens_mistral': 869, 'n_tokens_neox': 846, 'n_words': 165}