Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/reactivity/cref.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { IsNull, Ref, RefContent, RefParam, SRef, UnwrapRef } from '../api/types'
import {
IsNull,
Ref,
RefContent,
RefParam,
SRef,
UnwrapRef,
} from '../api/types'
import { flatten } from '../misc/flatten'
import { ref } from './ref'

Expand Down
4 changes: 2 additions & 2 deletions src/reactivity/ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import { refSymbol } from './refSymbols'
import { sref } from './sref'

/**
* The ref function mutates given value in place. Use it with caution.
* The ref function mutates given value in place. Use it with caution.
* If you need to create ref without mutating use cref (which is slower).
*
*
* Converts the given value and its nested properties into ref objects recursively and returns the ref.
* The returned object's type reflects its nested properties as well.
*
Expand Down
35 changes: 35 additions & 0 deletions tests/app/createApp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,41 @@ test('interpolation supports both syntaxes at once', () => {
expect(root.textContent).toBe('hello world')
})

test('interpolation preserves authored text spacing', () => {
const root = document.createElement('div')
const first = ref('Ada')
const last = ref('Lovelace')
createApp(
{
first,
last,
},
{
element: root,
template: html`<section>
<p id="joined">{{ first }}{{ last }}</p>
<p id="spaced">{{ first }} {{ last }}</p>
<p id="mixed">Hello {{ first }}!</p>
<p id="whole">{{ first }}</p>
</section>`,
},
)

expect(root.querySelector('#joined')?.textContent).toBe('AdaLovelace')
expect(root.querySelector('#spaced')?.textContent).toBe('Ada Lovelace')
expect(root.querySelector('#mixed')?.textContent).toBe('Hello Ada!')
expect(root.querySelector('#whole')?.textContent).toBe('Ada')
expect(root.querySelector('p > span')).toBeNull()

first('Grace')
last('Hopper')
expect(root.querySelector('#joined')?.textContent).toBe('GraceHopper')
expect(root.querySelector('#spaced')?.textContent).toBe('Grace Hopper')
expect(root.querySelector('#mixed')?.textContent).toBe('Hello Grace!')
expect(root.querySelector('#whole')?.textContent).toBe('Grace')
expect(root.querySelector('p > span')).toBeNull()
})

test('interpolation removes only generated spans and keeps cleanup anchored', () => {
const root = document.createElement('div')
const message = ref('hello')
Expand Down
20 changes: 11 additions & 9 deletions tests/directives/r-for.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ test('should mount the people into reactive divs.', () => {
expect(rows.map((x) => x.className)).toStrictEqual(
people.map((x) => x().name()),
)
expect(rows.map((x) => x.textContent?.replace(/\s+/g, ' ').trim()))
.toStrictEqual(
people.map((x, i) => {
const person = x()
return `${i} - name: ${person.name()} age: ${person.age()}`
}),
)
expect(
rows.map((x) => x.textContent?.replace(/\s+/g, ' ').trim()),
).toStrictEqual(
people.map((x, i) => {
const person = x()
return `${i} - name: ${person.name()} age: ${person.age()}`
}),
)
}
testContent()
people[0]().name.value = 'Ali'
Expand Down Expand Up @@ -128,8 +129,9 @@ test('should mount nested r-for.', () => {
),
)

expect(rows.map((x) => x.textContent?.replace(/\s+/g, ' ').trim()))
.toStrictEqual(
expect(
rows.map((x) => x.textContent?.replace(/\s+/g, ' ').trim()),
).toStrictEqual(
duplicateArray(
duplicate(),
people.map((x, i) => {
Expand Down
Loading