Skip to content

Commit

Permalink
initial value of inputs is observable.
Browse files Browse the repository at this point in the history
  • Loading branch information
loreanvictor committed Aug 25, 2023
1 parent f070caf commit 092def5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
Binary file removed misc/quel.sketch
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "quel",
"version": "0.3.3",
"version": "0.3.4",
"description": "Expression-based reactive library for hot listenables",
"main": "dist/commonjs/index.js",
"module": "dist/es/index.js",
Expand Down
2 changes: 2 additions & 0 deletions src/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export class InputSource extends Source<string> {
const handler = (evt: Event) => emit((evt.target as HTMLInputElement).value)
addListener(node, 'input', handler)

emit(node.value)

return () => removeListener(node, 'input', handler)
})
}
Expand Down
14 changes: 14 additions & 0 deletions src/test/input.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import { testRender } from 'test-callbag-jsx'
import { InputSource } from '../input'
import { observe } from '../observe'
import { Track } from '../types'


describe(InputSource, () => {
Expand Down Expand Up @@ -45,4 +47,16 @@ describe(InputSource, () => {
expect(cb).not.toHaveBeenCalled()
})
})

test('initial value is also observable.', () => {
testRender((renderer, {render, $}) => {
render(<input type='text' value='foo'/>)
const src = new InputSource($('input').resolveOne()! as HTMLInputElement)
const cb = jest.fn()

observe((_: Track) => cb(_(src)))

expect(cb).toHaveBeenCalledWith('foo')
})
})
})

0 comments on commit 092def5

Please sign in to comment.