-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec513ce
commit 42febf6
Showing
8 changed files
with
1,050 additions
and
212 deletions.
There are no files selected for viewing
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,12 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Solid Playground</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/index.jsx"></script> | ||
</body> | ||
</html> |
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,20 @@ | ||
{ | ||
"name": "playground", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"dom-expressions": "workspace:*", | ||
"s-js": "0.4.9" | ||
}, | ||
"devDependencies": { | ||
"babel-plugin-jsx-dom-expressions": "workspace:*", | ||
"vite": "^5.4.10", | ||
"vite-plugin-solid": "^2.10.2" | ||
} | ||
} |
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 @@ | ||
export * from "dom-expressions/src/client.js"; |
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,24 @@ | ||
import { render } from "./dom.js"; | ||
import * as s from "./rxcore.js"; | ||
|
||
const count = s.value(0); | ||
const increment = () => count(count() + 1); | ||
const s0 = () => (count() % 2 ? "ok" : [1, 2]); | ||
|
||
render(function App() { | ||
return ( | ||
<> | ||
<button type="button" onClick={increment}> | ||
{s0()} | ||
</button> | ||
<pre | ||
ref={ref => { | ||
ref.prepend("x"); | ||
queueMicrotask(() => ref.append("y")); | ||
}} | ||
> | ||
{s0()} | ||
</pre> | ||
</> | ||
); | ||
}, document.getElementById("root")); |
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,96 @@ | ||
import S from "s-js"; | ||
const { root, value, sample } = S; | ||
export { value, sample }; | ||
|
||
const getOwner = null; | ||
const sharedConfig = { | ||
getNextContextId() { | ||
return this.context.id + this.context.count++; | ||
} | ||
}; | ||
|
||
function memo(fn) { | ||
const s = value(sample(fn)); | ||
S(() => s(fn())); | ||
return s; | ||
} | ||
|
||
function createComponent(Comp, props) { | ||
if (Comp.prototype && Comp.prototype.isClassComponent) { | ||
return sample(() => { | ||
const comp = new Comp(props); | ||
return comp.render(props); | ||
}); | ||
} | ||
return sample(() => Comp(props)); | ||
} | ||
|
||
const propTraps = { | ||
get(_, property) { | ||
return _.get(property); | ||
}, | ||
has(_, property) { | ||
return _.has(property); | ||
}, | ||
set: trueFn, | ||
deleteProperty: trueFn, | ||
getOwnPropertyDescriptor(_, property) { | ||
return { | ||
configurable: true, | ||
enumerable: true, | ||
get() { | ||
return _.get(property); | ||
}, | ||
set: trueFn, | ||
deleteProperty: trueFn | ||
}; | ||
}, | ||
ownKeys(_) { | ||
return _.keys(); | ||
} | ||
}; | ||
|
||
function trueFn() { | ||
return true; | ||
} | ||
|
||
function resolveSource(s) { | ||
return (s = typeof s === "function" ? s() : s) == null ? {} : s; | ||
} | ||
|
||
function mergeProps(...sources) { | ||
return new Proxy( | ||
{ | ||
get(property) { | ||
for (let i = sources.length - 1; i >= 0; i--) { | ||
const v = resolveSource(sources[i])[property]; | ||
if (v !== undefined) return v; | ||
} | ||
}, | ||
has(property) { | ||
for (let i = sources.length - 1; i >= 0; i--) { | ||
if (property in resolveSource(sources[i])) return true; | ||
} | ||
return false; | ||
}, | ||
keys() { | ||
const keys = []; | ||
for (let i = 0; i < sources.length; i++) | ||
keys.push(...Object.keys(resolveSource(sources[i]))); | ||
return [...new Set(keys)]; | ||
} | ||
}, | ||
propTraps | ||
); | ||
} | ||
|
||
export { | ||
root, | ||
S as effect, | ||
memo, | ||
createComponent, | ||
getOwner, | ||
sharedConfig, | ||
sample as untrack, | ||
mergeProps | ||
}; |
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,42 @@ | ||
import { defineConfig } from "vite"; | ||
import { transformAsync } from "@babel/core"; | ||
import dom from "babel-plugin-jsx-dom-expressions"; | ||
export default defineConfig({ | ||
plugins: [ | ||
{ | ||
async transform(code, id) { | ||
if (!/.[tj]sx$/.test(id)) return; | ||
const result = await transformAsync(code, { | ||
plugins: [ | ||
[ | ||
dom, | ||
{ | ||
moduleName: "./dom", | ||
generate: "dom", | ||
hydratable: false, | ||
delegateEvents: true, | ||
delegatedEvents: [], | ||
builtIns: [], | ||
requireImportSource: false, | ||
wrapConditionals: true, | ||
omitNestedClosingTags: false, | ||
contextToCustomElements: false, | ||
staticMarker: "@once", | ||
effectWrapper: "effect", | ||
memoWrapper: "memo", | ||
validate: true | ||
} | ||
] | ||
] | ||
}); | ||
return result.code; | ||
} | ||
} | ||
], | ||
esbuild: { jsx: "preserve" }, | ||
resolve: { | ||
alias: { | ||
rxcore: "/src/rxcore.js" | ||
} | ||
} | ||
}); |
Oops, something went wrong.