Skip to content
Merged

Next #307

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
6 changes: 3 additions & 3 deletions client/rerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ function _rerender(current, next) {
}

if (current.type === 'textarea') {
current.value = current.children[0].text
next.value = next.children[0].text
updateAttributes(selector, current, next)
current.attributes.value = current.children[0].text
next.attributes.value = next.children[0].text
updateAttributes(selector, current.attributes, next.attributes)
return
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nullstack",
"version": "0.17.2",
"version": "0.17.3",
"description": "Full Stack Javascript Components for one-dev armies",
"main": "nullstack.js",
"author": "Mortaro",
Expand Down
7 changes: 6 additions & 1 deletion tests/src/TwoWayBindings.njs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class TwoWayBindings extends Nullstack {
debouncedEvent = '69'
debounceTime = 1000

textareaDisabled = false

parse({ event, source: bind, callback }) {
const normalized = event.target.value.replace(',', '').padStart(3, '0')
const whole = (parseInt(normalized.slice(0, -2)) || 0).toString()
Expand Down Expand Up @@ -68,10 +70,13 @@ class TwoWayBindings extends Nullstack {
{!this.boolean && <div data-boolean-type={typeof this.boolean} />}
{this.number > 1 && <div data-number-type={typeof this.number} />}
<input bind={this.number} name="number" oninput={this.updateCharacter} />
<textarea bind={this.text} name="text" />
<textarea bind={this.text} name="text" disabled={this.textareaDisabled} />
<button onclick={{ text: 'bbbb' }} data-textarea data-text={this.text}>
textarea b
</button>
<button onclick={{ textareaDisabled: true }} data-textarea-disabled>
textarea disable
</button>
<div data-character={this.character} />
<select bind={this.character} name="character">
{this.array.map((character) => (
Expand Down
14 changes: 14 additions & 0 deletions tests/src/TwoWayBindings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,27 @@ describe('TwoWayBindings', () => {
expect(value).toMatch('aaaa')
})

test('textareas changes reflects variable value', async () => {
await page.type('textarea', 'new')
await page.waitForSelector('[data-text="newaaaa"]')
const element = await page.$('[data-text="newaaaa"]')
expect(element).toBeTruthy()
})

test('textareas value reflects variable changes', async () => {
await page.click('[data-textarea]')
await page.waitForSelector('[data-text="bbbb"]')
const value = await page.$eval('textarea', (element) => element.value)
expect(value).toMatch('bbbb')
})

test('textareas attributes reflect variable changes', async () => {
await page.click('[data-textarea-disabled]')
await page.waitForSelector('textarea[disabled]')
const element = await page.$('textarea[disabled]')
expect(element).toBeTruthy()
})

test('checkboxes value reflects variable changes', async () => {
await page.click('[data-checkbox]')
await page.waitForSelector('input[type=checkbox]:not(:checked)')
Expand Down
2 changes: 1 addition & 1 deletion workers/dynamicFetch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
function dynamicStrategy(event) {
event.waitUntil(
(async function () {
if (event.request.method !== 'GET') return
const url = new URL(event.request.url)
for (const matcher of self.context.worker.staleWhileRevalidate) {
if (match(matcher, url)) {
Expand All @@ -13,7 +14,6 @@ function dynamicStrategy(event) {
}
}
if (url.origin !== location.origin) return
if (event.request.method !== 'GET') return
if (url.pathname.indexOf('/nullstack/') > -1) {
return event.respondWith(networkFirst(event))
}
Expand Down
2 changes: 1 addition & 1 deletion workers/staticFetch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
function staticStrategy(event) {
event.waitUntil(
(async function () {
if (event.request.method !== 'GET') return
const url = new URL(event.request.url)
for (const matcher of self.context.worker.staleWhileRevalidate) {
if (match(matcher, url)) {
Expand All @@ -13,7 +14,6 @@ function staticStrategy(event) {
}
}
if (url.origin !== location.origin) return
if (event.request.method !== 'GET') return
if (url.pathname.indexOf('/nullstack/') > -1) {
return event.respondWith(networkFirst(event))
}
Expand Down