-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
190 additions
and
24 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es2016", | ||
"jsx": "preserve", | ||
"baseUrl": "./src", | ||
"checkJs": true | ||
}, | ||
"exclude": ["node_modules", "**/node_modules/*"] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,18 @@ | ||
import { CharactersDetailsContainer } from './containers/CharactersDetailsContainer/CharactersDetailsContainer'; | ||
import { CharactersListContainer } from './containers/CharactersListContainer/CharactersListContainer'; | ||
import { dependencies } from './dependencies'; | ||
import { create } from './utils/renderer'; | ||
|
||
export const App = (DI) => { | ||
console.log(DI); | ||
const router = DI.getDependency(dependencies.router); | ||
|
||
router.setRoutePageRender('/', () => CharactersListContainer(DI)); | ||
router.setRoutePageRender('/character/.*', () => | ||
CharactersDetailsContainer(DI) | ||
); | ||
router.setNotFoundPage(() => | ||
create('div', { innerText: 'Page Not Found! Try another route :)' }) | ||
); | ||
|
||
return router.renderFromRouter(); | ||
}; |
4 changes: 2 additions & 2 deletions
4
courses/frontend-architecture/src/components/CharacterDetails/CharacterDetails.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import { create } from '../../utils/renderer'; | ||
|
||
export const CharacterDetails = (name, link, imgUrl) => { | ||
export const CharacterDetails = ({ name, link, imageUrl }) => { | ||
return create('div', {}, [ | ||
create('div', {}, [ | ||
create('span', { innerText: 'Character Name:' }), | ||
create('span', { innerText: name }), | ||
]), | ||
create('img', { src: imgUrl }), | ||
create('div', {}, [create('img', { src: imageUrl })]), | ||
create('a', { innerText: 'More details', href: link }), | ||
]); | ||
}; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export const EnvironmentConfigs = () => { | ||
return { | ||
endpoint: 'https://api.disneyapi.dev/characters', | ||
endpoint: 'https://api.disneyapi.dev', | ||
}; | ||
}; |
31 changes: 31 additions & 0 deletions
31
...tend-architecture/src/containers/CharactersDetailsContainer/CharactersDetailsContainer.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { CharacterDetails } from '../../components/CharacterDetails/CharacterDetails'; | ||
import { dependencies } from '../../dependencies'; | ||
import { create, onMountedFactory } from '../../utils/renderer'; | ||
|
||
const onMounted = onMountedFactory(); | ||
|
||
export const CharactersDetailsContainer = (DI) => { | ||
const charactersStore = DI.getDependency(dependencies.charactersStore); | ||
const router = DI.getDependency(dependencies.router); | ||
const currentRoute = router.getCurrentRoute(); | ||
const characterId = currentRoute.replace('/character/', ''); | ||
|
||
onMounted(() => charactersStore.fetchCharacter(characterId)); | ||
|
||
const character = charactersStore.characters[characterId]; | ||
|
||
console.log(character); | ||
|
||
return character | ||
? create('div', {}, [ | ||
create('a', { innerText: '<- back home', href: '/' }), | ||
create('a', { href: `/character/${character._id}` }, [ | ||
CharacterDetails({ | ||
name: character.name, | ||
url: character.url, | ||
imageUrl: character.imageUrl, | ||
}), | ||
]), | ||
]) | ||
: create('div'); | ||
}; |
Empty file.
26 changes: 26 additions & 0 deletions
26
...s/frontend-architecture/src/containers/CharactersListContainer/CharactersListContainer.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { CharacterItem } from '../../components/CharacterItem'; | ||
import { dependencies } from '../../dependencies'; | ||
import { create, onMountedFactory } from '../../utils/renderer'; | ||
|
||
const onMounted = onMountedFactory(); | ||
|
||
export const CharactersListContainer = (DI) => { | ||
const charactersStore = DI.getDependency(dependencies.charactersStore); | ||
|
||
onMounted(() => charactersStore.fetchCharacters()); | ||
|
||
const characters = Object.values(charactersStore.characters); | ||
|
||
return create('div', {}, [ | ||
create('div', { innerText: 'List of Disney Characters' }), | ||
create( | ||
'ul', | ||
{}, | ||
characters.map((character) => | ||
create('a', { href: `/character/${character._id}` }, [ | ||
CharacterItem(character.name), | ||
]) | ||
) | ||
), | ||
]); | ||
}; |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { DependencyContainer } from './stores/dependencyContainer.store'; | ||
import { ApiAdapter } from './adapters/apiAdapter'; | ||
import { EnvironmentConfigs } from './config/env'; | ||
import { RouterStore } from './stores/router.store'; | ||
import { CharactersApiService } from './services/CharactersApi.service'; | ||
import { CharactersStore } from './stores/Characters.store'; | ||
|
||
const dependenciesContainer = new DependencyContainer(); | ||
|
||
const dependencies = { | ||
env: Symbol('env'), | ||
api: Symbol('api'), | ||
router: Symbol('router'), | ||
charactersService: Symbol('charactersService'), | ||
charactersStore: Symbol('charactersStore'), | ||
}; | ||
|
||
const env = EnvironmentConfigs(); | ||
const api = new ApiAdapter(env); | ||
const router = new RouterStore(); | ||
const charactersService = new CharactersApiService(api); | ||
const charactersStore = new CharactersStore(charactersService); | ||
|
||
dependenciesContainer.add(dependencies.env, env); | ||
dependenciesContainer.add(dependencies.api, api); | ||
dependenciesContainer.add(dependencies.router, router); | ||
dependenciesContainer.add(dependencies.charactersService, charactersService); | ||
dependenciesContainer.add(dependencies.charactersStore, charactersStore); | ||
|
||
export { dependencies, dependenciesContainer }; |
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
13 changes: 13 additions & 0 deletions
13
courses/frontend-architecture/src/services/CharactersApi.service.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export class CharactersApiService { | ||
constructor(api) { | ||
this.api = api; | ||
} | ||
|
||
all() { | ||
return this.api.get('/characters'); | ||
} | ||
|
||
getCharacter(id) { | ||
return this.api.get(`/characters/${id}`); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
courses/frontend-architecture/src/stores/Characters.store.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { rerender } from '../utils/renderer'; | ||
|
||
export class CharactersStore { | ||
constructor(charactersApiService) { | ||
this.charactersApi = charactersApiService; | ||
this.characters = {}; | ||
} | ||
|
||
fetchCharacters() { | ||
this.charactersApi.all().then((response) => { | ||
response.data.forEach((character) => { | ||
this.characters[character._id] = character; | ||
}); | ||
rerender(); | ||
}); | ||
} | ||
|
||
fetchCharacter(id) { | ||
this.charactersApi.getCharacter(id).then((character) => { | ||
this.characters = { | ||
...this.characters, | ||
[character._id]: character, | ||
}; | ||
rerender(); | ||
}); | ||
} | ||
} |
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
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
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
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