-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(v2): new signals implementation (#6443)
feat(v2): new signals implementation (#6443) --------- Co-authored-by: Wout Mertens <[email protected]> Co-authored-by: Varixo <[email protected]> Co-authored-by: Jack Shelton <[email protected]>
- Loading branch information
1 parent
b6ac7d3
commit 6c4c5b9
Showing
81 changed files
with
3,411 additions
and
1,360 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { isQrl } from '../server/prefetch-strategy'; | ||
import { isJSXNode } from './render/jsx/jsx-runtime'; | ||
import { isTask } from './use/use-task'; | ||
import { vnode_isVNode, vnode_toString } from './v2/client/vnode'; | ||
import { ComputedSignal, WrappedSignal, isSignal } from './v2/signal/v2-signal'; | ||
import { isStore } from './v2/signal/v2-store'; | ||
|
||
const stringifyPath: any[] = []; | ||
export function qwikDebugToString(value: any): any { | ||
if (value === null) { | ||
return 'null'; | ||
} else if (value === undefined) { | ||
return 'undefined'; | ||
} else if (typeof value === 'string') { | ||
return '"' + value + '"'; | ||
} else if (typeof value === 'number' || typeof value === 'boolean') { | ||
return String(value); | ||
} else if (isTask(value)) { | ||
return `Task(${qwikDebugToString(value.$qrl$)})`; | ||
} else if (isQrl(value)) { | ||
return `Qrl(${value.$symbol$})`; | ||
} else if (typeof value === 'object' || typeof value === 'function') { | ||
if (stringifyPath.includes(value)) { | ||
return '*'; | ||
} | ||
if (stringifyPath.length > 10) { | ||
// debugger; | ||
} | ||
try { | ||
stringifyPath.push(value); | ||
if (Array.isArray(value)) { | ||
if (vnode_isVNode(value)) { | ||
return vnode_toString.apply(value); | ||
} else { | ||
return value.map(qwikDebugToString); | ||
} | ||
} else if (isSignal(value)) { | ||
if (value instanceof WrappedSignal) { | ||
return 'WrappedSignal'; | ||
} else if (value instanceof ComputedSignal) { | ||
return 'ComputedSignal'; | ||
} else { | ||
return 'Signal'; | ||
} | ||
} else if (isStore(value)) { | ||
return 'Store'; | ||
} else if (isJSXNode(value)) { | ||
return jsxToString(value); | ||
} | ||
} finally { | ||
stringifyPath.pop(); | ||
} | ||
} | ||
return value; | ||
} | ||
|
||
export const pad = (text: string, prefix: string) => { | ||
return String(text) | ||
.split('\n') | ||
.map((line, idx) => (idx ? prefix : '') + line) | ||
.join('\n'); | ||
}; | ||
|
||
export const jsxToString = (value: any): string => { | ||
if (isJSXNode(value)) { | ||
let type = value.type; | ||
if (typeof type === 'function') { | ||
type = type.name || 'Component'; | ||
} | ||
let str = '<' + value.type; | ||
if (value.props) { | ||
for (const [key, val] of Object.entries(value.props)) { | ||
str += ' ' + key + '=' + qwikDebugToString(val); | ||
} | ||
const children = value.children; | ||
if (children != null) { | ||
str += '>'; | ||
if (Array.isArray(children)) { | ||
children.forEach((child) => { | ||
str += jsxToString(child); | ||
}); | ||
} else { | ||
str += jsxToString(children); | ||
} | ||
str += '</' + value.type + '>'; | ||
} else { | ||
str += '/>'; | ||
} | ||
} | ||
return str; | ||
} else { | ||
return String(value); | ||
} | ||
}; |
This file contains 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
Oops, something went wrong.