Last active
May 30, 2017 13:43
-
-
Save camilleriluke/e353272c037e899b2606c21b1890ad24 to your computer and use it in GitHub Desktop.
✔️ Simple type annotated flow example
This file contains 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 characters
// @flow | |
import type {KnockoutComputed, KnockoutObservable} from 'knockout'; | |
import ko from 'knockout'; | |
interface FooJSON { | |
name: string; | |
surname: string; | |
} | |
interface FooModel { | |
name: KnockoutObservable<string>; | |
surname: KnockoutObservable<string>; | |
fullName: KnockoutComputed<string>; | |
} | |
type FooFactory = (input: FooJSON) => FooModel; | |
const fooFactory: FooFactory = payload => { | |
const name = ko.observable(payload.name); | |
const surname = ko.observable(payload.surname); | |
return { | |
name, | |
surname, | |
fullName: ko.pureComputed(() => { | |
return `${name()} ${surname()}`; | |
}) | |
}; | |
}; | |
export default fooFactory; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ah, this will be amazing :)