Skip to content

Instantly share code, notes, and snippets.

@camilleriluke
Last active May 30, 2017 13:43
Show Gist options
  • Save camilleriluke/e353272c037e899b2606c21b1890ad24 to your computer and use it in GitHub Desktop.
Save camilleriluke/e353272c037e899b2606c21b1890ad24 to your computer and use it in GitHub Desktop.
✔️ Simple type annotated flow example
// @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;
@Nostrus
Copy link

Nostrus commented May 30, 2017

Ah, this will be amazing :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment