aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoris2023-02-19 13:16:53 +0100
committerJoris2023-02-19 13:25:29 +0100
commit8b84a732436fc6c84ce4b912b548648eb91c9312 (patch)
tree9b86b1a4c14f6e8bd83013644cd29f954e590afe
parente1aaa513a444a32c56a9591dd92beb24e66bcf42 (diff)
downloadrx-8b84a732436fc6c84ce4b912b548648eb91c9312.tar.gz
rx-8b84a732436fc6c84ce4b912b548648eb91c9312.tar.bz2
rx-8b84a732436fc6c84ce4b912b548648eb91c9312.zip
Rename withVar to withState
-rw-r--r--src/example.ts24
-rw-r--r--src/rx.ts34
2 files changed, 30 insertions, 28 deletions
diff --git a/src/example.ts b/src/example.ts
index 1362fbd..5ff3fba 100644
--- a/src/example.ts
+++ b/src/example.ts
@@ -1,7 +1,7 @@
-import { h, withVar, mount, RxAble } from 'rx'
+import { h, withState, mount, sequence2, RxAble } from 'rx'
const imbricatedMaps =
- withVar(1, counter => [
+ withState(1, counter => [
counterComponent({
value: counter,
onSub: () => counter.update(n => n - 1),
@@ -20,7 +20,7 @@ const imbricatedMaps =
])
const flatMap =
- withVar(1, counter => [
+ withState(1, counter => [
counterComponent({
value: counter,
onSub: () => counter.update(n => n - 1),
@@ -36,7 +36,7 @@ const flatMap =
])
const checkbox =
- withVar(false, checked => [
+ withState(false, checked => [
checkboxComponent({
label: 'Checkbox',
isChecked: checked,
@@ -46,7 +46,7 @@ const checkbox =
])
const rxChildren =
- withVar(3, count => [
+ withState(3, count => [
h('input', {
type: 'number',
value: count,
@@ -60,7 +60,7 @@ const rxChildren =
])
const nodesCancel =
- withVar(false, checked => [
+ withState(false, checked => [
checkboxComponent({
label: 'Checkbox',
isChecked: checked,
@@ -70,7 +70,7 @@ const nodesCancel =
])
const counters =
- withVar<Array<number>>([], counters => {
+ withState<Array<number>>([], counters => {
return [
counterComponent({
value: counters.map(cs => cs.length),
@@ -97,7 +97,7 @@ const counters =
})
const rows =
- withVar(1, count => [
+ withState(1, count => [
h('input', {
type: 'number',
value: count,
@@ -107,13 +107,13 @@ const rows =
])
const chrono =
- withVar(false, isChecked => [
+ withState(false, isChecked => [
checkboxComponent({
label: 'Show counter',
isChecked,
onCheck: b => isChecked.update(_ => b)
}),
- isChecked.map(b => b && withVar(0, elapsed => {
+ isChecked.map(b => b && withState(0, elapsed => {
const interval = window.setInterval(
() => elapsed.update(n => n + 1),
1000
@@ -127,8 +127,8 @@ const chrono =
])
const doubleMapChild =
- withVar(true, isEven =>
- withVar('', search => {
+ withState(true, isEven =>
+ withState('', search => {
const books = [...Array(50).keys()]
const filteredBooks = isEven.flatMap(f => search.map(s =>
diff --git a/src/rx.ts b/src/rx.ts
index 5028ec1..ea4f6a4 100644
--- a/src/rx.ts
+++ b/src/rx.ts
@@ -1,14 +1,16 @@
+// Rx 1.0.1
+
// Html
export type Html
- = false
- | undefined
- | string
- | number
- | Tag
- | WithVar<any>
+ = false
+ | undefined
+ | string
+ | number
+ | Tag
+ | WithState<any>
| Array<Html>
- | Rx<Html>
+ | Rx<Html>
interface Tag {
type: 'Tag'
@@ -19,8 +21,8 @@ interface Tag {
onunmount?: (element: Element) => void
}
-interface WithVar<A> {
- type: 'WithVar'
+interface WithState<A> {
+ type: 'WithState'
init: A
getChildren: (v: Var<A>) => Html
}
@@ -40,8 +42,8 @@ type AttributeValue
function isHtml(x: any): x is Html {
return (typeof x === 'string'
|| typeof x === 'number'
- || isTag(x)
- || isWithVar(x)
+ || isTag(x)
+ || isWithState(x)
|| isRx(x)
|| Array.isArray(x))
}
@@ -88,9 +90,9 @@ export function h(
}
}
-export function withVar<A>(init: A, getChildren: (v: Var<A>) => Html): WithVar<A> {
+export function withState<A>(init: A, getChildren: (v: Var<A>) => Html): WithState<A> {
return {
- type: 'WithVar',
+ type: 'WithState',
init,
getChildren
}
@@ -322,7 +324,7 @@ function appendChild(state: State, element: Element, child: Html, lastAdded?: No
remove: () => element.removeChild(childElement),
lastAdded: childElement,
}
- } else if (isWithVar(child)) {
+ } else if (isWithState(child)) {
const { init, getChildren } = child
const v = state.register(init)
const children = getChildren(v)
@@ -374,8 +376,8 @@ function isTag<A>(x: any): x is Tag {
return x !== undefined && x.type === "Tag"
}
-function isWithVar<A>(x: any): x is WithVar<A> {
- return x !== undefined && x.type === "WithVar"
+function isWithState<A>(x: any): x is WithState<A> {
+ return x !== undefined && x.type === "WithState"
}
function appendNode(base: Element, node: Node, lastAdded?: Node) {