Skip to content

Commit

Permalink
XF removed
Browse files Browse the repository at this point in the history
  • Loading branch information
ackava committed Jan 12, 2024
1 parent 7239d4b commit 8cc2e1c
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 1,017 deletions.
430 changes: 0 additions & 430 deletions src/core/AtomBridge.ts

This file was deleted.

55 changes: 26 additions & 29 deletions src/core/AtomComponent.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { App } from "../App";
import { AtomBridge } from "../core/AtomBridge";
import { ArrayHelper, CancelToken, IAnyInstanceType, IAtomElement,
IDisposable, ignoreValue, INotifyPropertyChanged, PathList } from "../core/types";
import { Inject } from "../di/Inject";
import { NavigationService } from "../services/NavigationService";
import type { AtomControl } from "../web/controls/AtomControl";
import { AtomDisposableList } from "./AtomDisposableList";
import { AtomOnce } from "./AtomOnce";
import { AtomWatcher, ObjectProperty } from "./AtomWatcher";
import Bind, { bindSymbol } from "./Bind";
import { setValue, visitDescendents, watchProperty } from "./Hacks";
import { InheritedProperty } from "./InheritedProperty";
import { IValueConverter } from "./IValueConverter";
import { PropertyMap } from "./PropertyMap";
Expand Down Expand Up @@ -50,16 +51,11 @@ const isFactory = isFactorySymbol;

const isAtomControl = isControl;

const localBridge = AtomBridge;

const renderFirst = AtomBridge.platform === "xf";

const attached = attachedSymbol;

const constructorNeedsArguments = constructorNeedsArgumentsSymbol;

export abstract class AtomComponent<T extends IAtomElement, TC extends IAtomComponent<T>>
implements IAtomComponent<IAtomElement>,
export abstract class AtomComponent implements
INotifyPropertyChanged {

public static readonly [isControl] = true;
Expand All @@ -69,7 +65,7 @@ export abstract class AtomComponent<T extends IAtomElement, TC extends IAtomComp
// public element: T;
public readonly disposables: AtomDisposableList;

public readonly element: T;
public readonly element: HTMLElement;

@InheritedProperty
public data: any;
Expand Down Expand Up @@ -145,7 +141,7 @@ export abstract class AtomComponent<T extends IAtomElement, TC extends IAtomComp
// AtomBridge.refreshInherited(this, "localViewModel");
// }

public abstract get parent(): TC;
public abstract get parent(): AtomControl;

/** Do not ever use, only available as intellisense feature for
* vs code editor.
Expand All @@ -159,13 +155,13 @@ export abstract class AtomComponent<T extends IAtomElement, TC extends IAtomComp
// return AtomBridge.instance.templateParent(this.element);
// }

private readonly eventHandlers: Array<IEventObject<T>>;
private readonly eventHandlers: Array<IEventObject<HTMLElement>>;

private readonly bindings: Array<PropertyBinding<T>>;
private readonly bindings: Array<PropertyBinding>;

constructor(
@Inject public readonly app: App,
element: T = null) {
element: HTMLElement = null) {
this.disposables = new AtomDisposableList();
this.bindings = [];
this.eventHandlers = [];
Expand All @@ -178,10 +174,10 @@ export abstract class AtomComponent<T extends IAtomElement, TC extends IAtomComp
app.callLater(() => a.dispose());
}

public abstract atomParent(e: T): TC;
public abstract atomParent(e: HTMLElement): AtomControl;

public bind(
element: T,
element: HTMLElement,
name: string,
path: PathList[],
twoWays?: boolean | string[],
Expand Down Expand Up @@ -210,7 +206,7 @@ export abstract class AtomComponent<T extends IAtomElement, TC extends IAtomComp
* @param element T
* @param name string
*/
public unbind(element: T, name?: string): void {
public unbind(element: HTMLElement, name?: string): void {
const toDelete = this.bindings.filter( (x) => x.element === element && (!name || (x.name === name)));
for (const iterator of toDelete) {
iterator.dispose();
Expand All @@ -219,7 +215,7 @@ export abstract class AtomComponent<T extends IAtomElement, TC extends IAtomComp
}

public bindEvent(
element: T,
element: HTMLElement,
name?: string,
method?: EventListenerOrEventListenerObject,
key?: string,
Expand All @@ -230,7 +226,7 @@ export abstract class AtomComponent<T extends IAtomElement, TC extends IAtomComp
if (!method) {
return;
}
const be: IEventObject<T> = {
const be: IEventObject<HTMLElement> = {
element,
name,
handler: method
Expand Down Expand Up @@ -281,7 +277,7 @@ export abstract class AtomComponent<T extends IAtomElement, TC extends IAtomComp
}

public unbindEvent(
element: T,
element: HTMLElement,
name?: string,
method?: EventListenerOrEventListenerObject,
key?: string): void {
Expand Down Expand Up @@ -335,7 +331,7 @@ export abstract class AtomComponent<T extends IAtomElement, TC extends IAtomComp
* @param name string
* @param value any
*/
public setPrimitiveValue(element: T, name: string, value: any): void {
public setPrimitiveValue(element: HTMLElement, name: string, value: any): void {
const p = value as Promise<any>;
if (p && p.then && p.catch) {
// tslint:disable-next-line: no-console
Expand Down Expand Up @@ -372,7 +368,7 @@ export abstract class AtomComponent<T extends IAtomElement, TC extends IAtomComp
}
}

public setLocalValue(element: T, name: string, value: any): void {
public setLocalValue(element: HTMLElement, name: string, value: any): void {

// if value is a promise
const p = value as Promise<any>;
Expand Down Expand Up @@ -404,14 +400,14 @@ export abstract class AtomComponent<T extends IAtomElement, TC extends IAtomComp
}
}

public dispose(e?: T): void {
public dispose(e?: HTMLElement): void {

if (this.mInvalidated) {
clearTimeout(this.mInvalidated);
this.mInvalidated = 0;
}

AtomBridge.instance.visitDescendents(e || this.element, (ex, ac) => {
visitDescendents(e || this.element as any, (ex, ac) => {
if (ac) {
ac.dispose();
return false;
Expand Down Expand Up @@ -451,7 +447,7 @@ export abstract class AtomComponent<T extends IAtomElement, TC extends IAtomComp
}
}

public abstract append(element: T | TC): TC;
public abstract append(element: HTMLElement | AtomControl): AtomControl;

// tslint:disable-next-line:no-empty
public onPropertyChanged(name: string): void {
Expand Down Expand Up @@ -629,8 +625,9 @@ export abstract class AtomComponent<T extends IAtomElement, TC extends IAtomComp

}

protected setElementValue(element: T, name: string, value: any): void {
AtomBridge.instance.setValue(element, name, value);
protected setElementValue(element: HTMLElement, name: string, value: any): void {
// setValue(element, name, value);
element[name] = value;
}

protected resolve<TService>(
Expand Down Expand Up @@ -667,7 +664,7 @@ export abstract class AtomComponent<T extends IAtomElement, TC extends IAtomComp

}

export class PropertyBinding<T extends IAtomElement> implements IDisposable {
export class PropertyBinding implements IDisposable {

public path: ObjectProperty[][];

Expand All @@ -681,8 +678,8 @@ export class PropertyBinding<T extends IAtomElement> implements IDisposable {
private disposed: boolean;

constructor(
private target: IAtomComponent<T> | any,
public readonly element: T,
private target: AtomControl | any,
public readonly element: HTMLElement,
public readonly name: string,
path: PathList[],
private twoWays: boolean | string[],
Expand Down Expand Up @@ -763,7 +760,7 @@ export class PropertyBinding<T extends IAtomElement> implements IDisposable {
events = this.twoWays;
}

this.twoWaysDisposable = AtomBridge.instance.watchProperty(
this.twoWaysDisposable = watchProperty(
this.element,
this.name,
events,
Expand Down
62 changes: 62 additions & 0 deletions src/core/Hacks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import type { AtomControl } from "../web/controls/AtomControl";
import { ChildEnumerator } from "../web/core/AtomUI";
import { AtomBinder } from "./AtomBinder";
import { IDisposable } from "./types";

export const visitDescendents = (element: HTMLElement, action: (e: HTMLElement, ac: AtomControl) => boolean): void => {

for (const iterator of ChildEnumerator.enumerate(element)) {
const eAny = iterator as any;
const ac = eAny ? eAny.atomControl : undefined;
if (!action(iterator, ac)) {
continue;
}
visitDescendents(iterator, action);
}
}

export const refreshInherited = (target: AtomControl, name: string, fieldName?: string ) => {
AtomBinder.refreshValue(target, name);
if (!fieldName) {
fieldName = "m" + name[0].toUpperCase() + name.substr(1);
}
if (!target.element) {
return;
}
visitDescendents(target.element, (e, ac) => {
if (ac) {
if (ac[fieldName] === undefined) {
refreshInherited(ac as any, name, fieldName);
}
return false;
}
return true;
});
}

export const watchProperty = (element: HTMLElement, name: string, events: string[], f: (v: any) => void): IDisposable => {
if (events.indexOf("change") === -1) {
events.push("change");
}

const l = (e) => {
const e1 = element as HTMLInputElement;
const v = e1.type === "checkbox" ? e1.checked : e1.value;
f(v);
};
for (const iterator of events) {
element.addEventListener(iterator, l , false);
}

return {
dispose: () => {
for (const iterator of events) {
element.removeEventListener(iterator, l, false);
}
}
};
}

export const setValue = (element: HTMLElement, name: string, value: any) => {
element[name] = value;
}
2 changes: 1 addition & 1 deletion src/core/InjectProperty.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AtomComponent } from "./AtomComponent";

export default function InjectProperty(target: AtomComponent<any, any>, key: string): void {
export default function InjectProperty(target: AtomComponent, key: string): void {

Object.defineProperty(target, key, {
get: function() {
Expand Down
2 changes: 1 addition & 1 deletion src/core/WatchProperty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AtomBinder } from "./AtomBinder";
import type { AtomComponent } from "./AtomComponent";
import { AtomWatcher } from "./AtomWatcher";

export default function WatchProperty(target: AtomComponent<any, any>, key: string, descriptor: any): any {
export default function WatchProperty(target: AtomComponent, key: string, descriptor: any): any {

const { get } = descriptor;
const isSetup = Symbol.for(`isSetup${key}`);
Expand Down
19 changes: 9 additions & 10 deletions src/services/http/RestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { AjaxOptions } from "./AjaxOptions";

import { App } from "../../App";
import { Atom } from "../../Atom";
import { AtomBridge } from "../../core/AtomBridge";
import { CancelToken, INameValuePairs } from "../../core/types";
import { Inject } from "../../di/Inject";
import { TypeKey } from "../../di/TypeKey";
Expand Down Expand Up @@ -637,15 +636,15 @@ export class BaseService {
throw new Error("cancelled");
}

if (AtomBridge.instance.ajax) {
return await new Promise<AjaxOptions>((resolve, reject) => {
AtomBridge.instance.ajax(url, options, (r) => {
resolve(options);
}, (e) => {
reject(e);
}, null);
});
}
// if (AtomBridge.instance.ajax) {
// return await new Promise<AjaxOptions>((resolve, reject) => {
// AtomBridge.instance.ajax(url, options, (r) => {
// resolve(options);
// }, (e) => {
// reject(e);
// }, null);
// });
// }

const xhr = new XMLHttpRequest();

Expand Down
13 changes: 4 additions & 9 deletions src/web/controls/AtomControl.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { App } from "../../App";
import { AtomBinder } from "../../core/AtomBinder";
import { AtomBridge, AtomElementBridge } from "../../core/AtomBridge";
import { AtomComponent } from "../../core/AtomComponent";
import { AtomDispatcher } from "../../core/AtomDispatcher";
import { BindableProperty } from "../../core/BindableProperty";
import Command from "../../core/Command";
import FormattedString from "../../core/FormattedString";
import { refreshInherited, visitDescendents } from "../../core/Hacks";
import WebImage from "../../core/WebImage";
import XNode, { elementFactorySymbol, isControl } from "../../core/XNode";
import { TypeKey } from "../../di/TypeKey";
Expand All @@ -31,8 +31,6 @@ if (typeof bridge !== "undefined" && bridge.platform) {
throw new Error("AtomControl of Web should not be used with Xamarin Forms");
}

const bridgeInstance = AtomBridge.instance;

declare global {
// tslint:disable-next-line:interface-name
export interface HTMLElement {
Expand Down Expand Up @@ -257,7 +255,7 @@ export type PropertyRegistration = ((value) => ({[key: string]: any})) & {
/**
* AtomControl class represents UI Component for a web browser.
*/
export class AtomControl extends AtomComponent<HTMLElement, AtomControl> {
export class AtomControl extends AtomComponent {

public static from<T = AtomControl>(e1: Element | EventTarget): T {
let e = e1 as any;
Expand Down Expand Up @@ -338,7 +336,7 @@ export class AtomControl extends AtomComponent<HTMLElement, AtomControl> {
}
public set theme(v: AtomStyleSheet) {
this.mTheme = v;
bridgeInstance.refreshInherited(this, "theme");
refreshInherited(this, "theme");
}

/**
Expand Down Expand Up @@ -400,7 +398,7 @@ export class AtomControl extends AtomComponent<HTMLElement, AtomControl> {

public updateSize(): void {
this.onUpdateSize();
bridgeInstance.visitDescendents(this.element, (e, ac) => {
visitDescendents(this.element, (e, ac) => {
if (ac) {
ac.updateSize();
return false;
Expand Down Expand Up @@ -572,7 +570,6 @@ export class AtomControl extends AtomComponent<HTMLElement, AtomControl> {
const forName = attributes?.for;
const ctrl = new (name)(app,
forName ? document.createElement(forName) : undefined);
ctrl.creator = creator;
const element = ctrl.element ;
e?.appendChild(element);
ctrl.render(iterator, element, creator);
Expand Down Expand Up @@ -734,5 +731,3 @@ window.addEventListener("click", (e) => {
control.dispatchClickEvent(e, data);
}
});

bridgeInstance.controlFactory = AtomControl;
4 changes: 2 additions & 2 deletions src/web/controls/AtomGridView.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AtomBridge } from "../../core/AtomBridge";
import { BindableProperty } from "../../core/BindableProperty";
import { visitDescendents } from "../../core/Hacks";
import { IRect } from "../../core/types";
import { AtomControl } from "./AtomControl";

Expand Down Expand Up @@ -263,7 +263,7 @@ export class AtomGridView extends AtomControl {
host.style.left = `${colStart}px`;
host.style.width = `${colSize}px`;

AtomBridge.instance.visitDescendents(host, (el, ac) => {
visitDescendents(host, (el, ac) => {
if (ac) {
ac.invalidate();
return false;
Expand Down
Loading

0 comments on commit 8cc2e1c

Please sign in to comment.