Skip to content

Commit

Permalink
feat(dom): #90 - Dom support DomList base methods
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaodong2008 committed Feb 1, 2024
1 parent 4879b4d commit 63bfdfb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/dom/dom-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class FastjsDomList extends FastjsBaseModule<FastjsDomList> implements FastjsDom
readonly #effect: Function;
readonly construct: "FastjsDomList";

constructor(list: Array<HTMLElement | Element> = []) {
constructor(list: Array<HTMLElement | Element | FastjsDom> = []) {
if (__DEV__)
_dev.browserCheck("fastjs/dom/FastjsDomList")

Expand Down
41 changes: 32 additions & 9 deletions src/dom/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type {EventCallback, EventList, InsertReturn, PushReturn, FastjsDomProps,
import FastjsBaseModule from "../base";
import {InsertTarget, PushTarget} from "./def";


class FastjsDom extends FastjsBaseModule<FastjsDom>{
public readonly construct: string = "FastjsDom";
_events: EventList = [];
Expand All @@ -18,14 +17,6 @@ class FastjsDom extends FastjsBaseModule<FastjsDom>{
if (__DEV__)
_dev.browserCheck("fastjs/dom/Dom")

if (__DEV__ && el instanceof FastjsDom) {
_dev.warn("fastjs/dom/Dom", "wtf are you doing? el is already a Dom", [
"*el: ", el,
"constructor(**el: Dom | HTMLElement | Element | string**, properties?: FastjsDomProps)",
"super: ", this
], ["fastjs.wrong"]);
}

el = el instanceof FastjsDom ? el.el() : el;
// if string
if (typeof el === "string") {
Expand Down Expand Up @@ -583,6 +574,38 @@ class FastjsDom extends FastjsBaseModule<FastjsDom>{

return this;
}

// ==== DomList Base Function Support ==== //

getDom(key: number): FastjsDom {
if (__DEV__)
_dev.experimentFeatureWarning("dom-with-domlist", "DomList Base Function Support", "FastjsDom.getDom");
return this;
}

getElement(key: number): HTMLElement {
if (__DEV__)
_dev.experimentFeatureWarning("dom-with-domlist", "DomList Base Function Support", "FastjsDom.getElement");
return this.el();
}

toArray(): Array<FastjsDom> {
if (__DEV__)
_dev.experimentFeatureWarning("dom-with-domlist", "DomList Base Function Support", "FastjsDom.toArray")
return [this];
}

toElArray(): Array<HTMLElement> {
if (__DEV__)
_dev.experimentFeatureWarning("dom-with-domlist", "DomList Base Function Support", "FastjsDom.toElArray")
return [this._el];
}

each(callback: EachCallback): FastjsDomList {
if (__DEV__)
_dev.experimentFeatureWarning("dom-with-domlist", "DomList Base Function Support", "FastjsDom.each")
return new FastjsDomList([this]).each(callback);
}
}

export default FastjsDom

0 comments on commit 63bfdfb

Please sign in to comment.