Skip to content

Commit

Permalink
more todo, fix hickups, renable style
Browse files Browse the repository at this point in the history
  • Loading branch information
barelyhuman committed Oct 22, 2022
1 parent 9e83b00 commit 866cd48
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 15 deletions.
2 changes: 2 additions & 0 deletions dom/src/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ export function createDOM(rootTag) {
registry.reset()
registry.root = rootTag
var window = new Window()
// @ts-ignore
Object.assign(global, window)
return window.document
}
4 changes: 4 additions & 0 deletions dom/src/dom/binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export class Binding {
return this.props.get(key)
}

removeProp(key) {
return this.props.delete(key)
}

getAllProps() {
const res = {}
for (let [key, val] of Object.entries(this.props)) {
Expand Down
4 changes: 2 additions & 2 deletions dom/src/dom/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
FOCUS_EVENTS,
KEYBOARD_EVENTS,
} from './constants'
import { registry, TYPES } from './registry'
import { FALSE_TYPES, registry, TYPES } from './registry'
import { isSameChild } from './utils'

class Bridge {
Expand Down Expand Up @@ -79,7 +79,7 @@ class Bridge {
}
case 'create': {
const type = params[1]
if (type === '#document') {
if (Object.keys(FALSE_TYPES).indexOf(type) > -1) {
break
}
const rawViewClass = TYPES[type]
Expand Down
3 changes: 3 additions & 0 deletions dom/src/dom/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export class Document extends Element {
return new Event('')
}

// TODO:
createComment() {}

createElementNS(localName, nsURI) {
if (nsURI.contains('2000 / svg') > -1) {
return new SVGElement(localName)
Expand Down
15 changes: 9 additions & 6 deletions dom/src/dom/element.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
BINDING,
BINDING_NODE,
CURRENT_STYLE,
EVENTPHASE_AT_TARGET,
EVENTPHASE_BUBBLE,
Expand All @@ -11,6 +12,8 @@ import {
STYLE,
} from './constants'
import { EventTarget } from './event-target'
import { registry } from './registry'
import { Text } from './text'

export class Element extends EventTarget {
[NS] = 'http://www.w3.org/1999/xhtml'
Expand Down Expand Up @@ -124,12 +127,12 @@ export class Element extends EventTarget {

function createStyleBinding(id) {
let style = {}
// const binding = BINDINGS.get(id)
// Object.defineProperty(style, CURRENT_STYLE, { value: new Map() })
// Object.defineProperty(style, OWNER_NODE, {
// get: NODES.get.bind(NODES, binding),
// })
// return new Proxy(style, STYLE_PROXY)
const binding = registry.getBinding(id)
Object.defineProperty(style, CURRENT_STYLE, { value: new Map() })
Object.defineProperty(style, OWNER_NODE, {
get: () => binding[BINDING_NODE],
})
return new Proxy(style, STYLE_PROXY)
}

const STYLE_PROXY = {
Expand Down
8 changes: 8 additions & 0 deletions dom/src/dom/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ export class Node {
}

insertBefore(node, refNode) {
if (!node) {
return
}

if (!refNode) {
return this.appendChild(node)
}

const old = this.children.slice()
const index = getChildIndex(this, refNode)
const before = this.children.slice(0, index)
Expand Down
15 changes: 11 additions & 4 deletions dom/src/dom/registry.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
export const TYPES = {
'#text': {
type: 'RCTRawText',
},
export const FALSE_TYPES = {
'#document': {
type: 'Document',
},
'#fragment': {
type: 'DocumentFragment',
},
'template': {
type: 'DocumentFragment',
},
}

export const TYPES = {
...FALSE_TYPES,
'#text': {
type: 'RCTRawText',
},
}

class Registry {
Expand Down
5 changes: 2 additions & 3 deletions dom/src/dom/text.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Node } from './node'

import { BINDING, NODE_TYPES } from './constants'
import { EventTarget } from './event-target'

export class Text extends Node {
export class Text extends EventTarget {
constructor(data) {
super('#text', NODE_TYPES.TEXT_NODE)
this[BINDING].create()
Expand Down

0 comments on commit 866cd48

Please sign in to comment.