Skip to content

Commit

Permalink
Add a fp library and finish the repository implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrovgs committed Oct 18, 2018
1 parent 8fdfb67 commit deca78e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -16,6 +16,7 @@
},
"dependencies": {
"expo": "^30.0.1",
"fp-ts": "^1.9.0",
"react": "16.3.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-30.0.0.tar.gz",
"react-navigation": "^2.18.0",
Expand Down
12 changes: 8 additions & 4 deletions src/core/super-heroes-repository.ts
@@ -1,3 +1,4 @@
import { fromNullable, Option } from "fp-ts/lib/Option";
import { SuperHero } from "./model";

const superHeroes: SuperHero[] = [
Expand Down Expand Up @@ -102,12 +103,15 @@ const superHeroes: SuperHero[] = [

export function getSuperHeroes(): Promise<SuperHero[]> {
return new Promise<SuperHero[]>((resolve) => {
resolve(superHeroes);
setTimeout(() => resolve(superHeroes), 1500);
});
}

export function getSuperHeroById(id: string): Promise<SuperHero> {
return new Promise<SuperHero>((resolve) => {
superHeroes.filter((superHero) => superHero.name === id);
export function getSuperHeroById(id: string): Promise<Option<SuperHero>> {
return new Promise<Option<SuperHero>>((resolve) => {
setTimeout(() => {
const superHero = superHeroes.find((sh) => sh.name === id);
resolve(fromNullable(superHero));
}, 1500);
});
}
4 changes: 4 additions & 0 deletions yarn.lock
Expand Up @@ -2698,6 +2698,10 @@ form-data@~2.3.2:
combined-stream "^1.0.6"
mime-types "^2.1.12"

fp-ts@^1.9.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/fp-ts/-/fp-ts-1.9.0.tgz#52acf85692025b34285ff4014f39af72d1107e0b"

fragment-cache@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/fragment-cache/-/fragment-cache-0.2.1.tgz#4290fad27f13e89be7f33799c6bc5a0abfff0d19"
Expand Down

0 comments on commit deca78e

Please sign in to comment.