Last active
August 22, 2020 17:01
-
-
Save shiftyp/1a4fa5e28343b2aedee7a93c355b41c1 to your computer and use it in GitHub Desktop.
Revisions
-
shiftyp revised this gist
Aug 22, 2020 . No changes.There are no files selected for viewing
-
shiftyp revised this gist
Aug 22, 2020 . 1 changed file with 9 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ import React from 'react' import { useStable, useWatch } from '@objects/hooks' import { through, map, debounce } from '@objects/operators' interface Search { title: string @@ -13,31 +13,28 @@ interface Data { export const MovieSearch = () => { // Creates a stable object reference const [search] = useStable(() => ({ title: '', }) as Search) // Connects changes in the object's properties to component state updates useWatch(search)() // Connects changes in the object's title property to effects and computed state const movies: string[] = useWatch(search).title( through( debounce(), map((title: string) => ( fetch(`/api?q=${title}`) .then(resp => resp.json() as Promise<Data>) .then(data => data.results) )), ), [] ) return ( <div> <input value={search.title} onChange={(e) => { @@ -48,7 +45,6 @@ export const MovieSearch = () => { <ul> {movies.length ? movies.map(movie => <li>{movie}</li>) : <li>No Results</li>} </ul> </div> ) } -
shiftyp revised this gist
Aug 22, 2020 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ import React from 'react' import { useStable, useWatch } from '@objects/hooks' import { map, filter, dedupe, debounce } from '@objects/operators' interface Search { title: string @@ -26,6 +26,7 @@ export const MovieSearch = () => { map((title: string) => title.trim()), filter((title: string) => title.length), dedupe(), debounce(), map((title: string) => ( fetch(`/api?q=${title}`) .then(resp => resp.json()) as Promise<Data> -
shiftyp revised this gist
Aug 22, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -20,7 +20,7 @@ export const MovieSearch = () => { // Connects changes in the object's properties to component state updates useWatch(search)() // Connects changes in the object's title property to effects and computed state const movies = useWatch(search).title( through( map((title: string) => title.trim()), -
shiftyp revised this gist
Aug 22, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -18,7 +18,7 @@ export const MovieSearch = () => { } as Search) // Connects changes in the object's properties to component state updates useWatch(search)() // Connects changes in the object's properties to computed state const movies = useWatch(search).title( -
shiftyp revised this gist
Aug 22, 2020 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -12,12 +12,15 @@ interface Data { } export const MovieSearch = () => { // Creates a stable object reference const [search] = useStable(() => { title: '', } as Search) // Connects changes in the object's properties to component state updates useWatch(search).title() // Connects changes in the object's properties to computed state const movies = useWatch(search).title( through( map((title: string) => title.trim()), @@ -37,6 +40,7 @@ export const MovieSearch = () => { <input value={search.title} onChange={(e) => { // Mutate the object! search.title = e.target.value }} /> -
shiftyp revised this gist
Aug 22, 2020 . 1 changed file with 6 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -34,7 +34,12 @@ export const MovieSearch = () => { return ( <> <input value={search.title} onChange={(e) => { search.title = e.target.value }} /> <ul> {movies.length ? movies.map(movie => <li>{movie}</li>) : <li>No Results</li>} </ul> -
shiftyp revised this gist
Aug 22, 2020 . 1 changed file with 5 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -23,10 +23,10 @@ export const MovieSearch = () => { map((title: string) => title.trim()), filter((title: string) => title.length), dedupe(), map((title: string) => ( fetch(`/api?q=${title}`) .then(resp => resp.json()) as Promise<Data> )), map((data: Data) => data.results) ), [] @@ -36,12 +36,9 @@ export const MovieSearch = () => { <> <Input search={search} /> <ul> {movies.length ? movies.map(movie => <li>{movie}</li>) : <li>No Results</li>} </ul> </> ) }
-
shiftyp revised this gist
Aug 22, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,7 @@ export const MovieSearch = () => { filter((title: string) => title.length), dedupe(), map((title: string) => fetch(`/api?q=${title}`) .then(resp => resp.json()) as Promise<Data> ), map((data: Data) => data.results) -
shiftyp revised this gist
Aug 22, 2020 . 1 changed file with 3 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -20,27 +20,21 @@ export const MovieSearch = () => { const movies = useWatch(search).title( through( map((title: string) => title.trim()), filter((title: string) => title.length), dedupe(), map((title: string) => fetch(`/api/movies?title=${title}`) .then(resp => resp.json()) as Promise<Data> ), map((data: Data) => data.results) ), [] ) return ( <> <Input search={search} /> <ul> { movies.length ? -
shiftyp revised this gist
Aug 22, 2020 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ import React from 'react' import { useStable, useWatch } from '@objects/hooks' import { map, filter, dedupe } from '@objects/operators' interface Search { @@ -12,7 +12,7 @@ interface Data { } export const MovieSearch = () => { const [search] = useStable(() => { title: '', } as Search) -
shiftyp renamed this gist
Aug 22, 2020 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
shiftyp revised this gist
Aug 22, 2020 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -16,6 +16,8 @@ export const MovieSearch = () => { title: '', } as Search) useWatch(search).title() const movies = useWatch(search).title( through( map((title: string) => title.trim()) -
shiftyp revised this gist
Aug 22, 2020 . 1 changed file with 20 additions and 19 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,7 @@ import React from 'react' import { useCreate, useWatch } from '@objects/hooks' import { map, filter, dedupe } from '@objects/operators' interface Search { title: string @@ -20,31 +21,31 @@ export const MovieSearch = () => { map((title: string) => title.trim()) filter((title: string) => title.length), dedupe(), map((title: string) => fetch(`/api/movies?title=${title}`) .then(resp => resp.json()) as Promise<Data> ) map((data: Data) => data.results) ), [] ) return ( <> <input placeholder="Search for movies!" value={search.title} onChange={(e) => { search.title = e.target.value }} /> <ul> { movies.length ? movies.map(movie => <li>{movie}</li>) : <li>No Results</li> } </ul> </> ) } -
shiftyp revised this gist
Aug 22, 2020 . 1 changed file with 27 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,37 @@ import React from 'react' import { useCreate, useWatch } from '../../core' interface Search { title: string } interface Data { results: string[] } export const MovieSearch = () => { const [search] = useCreate(() => { title: '', } as Search) const movies = useWatch(search).title( through( map((title: string) => title.trim()) filter((title: string) => title.length), dedupe(), map((title: string) => fetch(`/api/movies?title=${title}`).then(resp => resp.json()) as Promise<Data>) map((data: Data) => data.results) ), [] ) return ( <> <Title search={search} /> <Movies movies={movies} /> </> ) } export const Title: React.FC<{ -
shiftyp revised this gist
Aug 22, 2020 . No changes.There are no files selected for viewing
-
shiftyp created this gist
Aug 22, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ import React from 'react' import { watch } from '../../core' interface Data { title: string } export const MovieSearch = () => { const [search] = create({ title: }) } export const Title: React.FC<{ editable: Data }> = ({ editable }) => { watch(editable).title() return ( <input value={editable.title} onChange={(e) => { editable.title = e.target.value }} /> ) }