Skip to content
This repository has been archived by the owner on Jun 22, 2021. It is now read-only.

Commit

Permalink
fix(deps): Updates JSE deps.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryasmi committed Mar 20, 2018
1 parent 32f81fb commit 44b5422
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 136 deletions.
38 changes: 23 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"check-coverage": true
},
"dependencies": {
"@js-entity-repos/core": "^6.0.2",
"@js-entity-repos/memory": "^3.0.1",
"@js-entity-repos/core": "^7.1.0",
"@js-entity-repos/memory": "^4.0.1",
"prop-types": "^15.6.0",
"react": "^16.2.0",
"react-dom": "^16.2.0",
Expand All @@ -50,7 +50,8 @@
"nyc": "11.6.0",
"parcel-bundler": "1.6.2",
"power-assert": "1.4.4",
"rimraf": "2.6.2"
"rimraf": "2.6.2",
"typescript": "2.8.0-rc"
},
"publishConfig": {
"access": "public"
Expand Down
5 changes: 0 additions & 5 deletions src/presenter/AppConfig.ts

This file was deleted.

7 changes: 0 additions & 7 deletions src/presenter/FactoryConfig.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/presenter/app.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import repoFactory from '../repo/factory';
import serviceFactory from '../service/factory';
import observer from '../utils/observer';
import AppConfig from './AppConfig';
import factory from './factory';

export default (config: AppConfig) => {
const repo = repoFactory(config.repo);
export default () => {
const emitChange = () => observer.emit('change');
const repo = repoFactory({ emitChange });
const service = serviceFactory({ repo });
const presenter = factory({ service, observer });

Expand Down
8 changes: 7 additions & 1 deletion src/presenter/factory.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { EventEmitter } from 'events';
import * as React from 'react';
import FactoryConfig from './FactoryConfig';
import serviceFactory from '../service/factory';
import Footer from './Footer';
import NewTodo from './NewTodo';
import TodoItems from './TodoItems';
import ConnectProvider from './utils/ConnectProvider';

export interface FactoryConfig {
readonly service: ReturnType<typeof serviceFactory>;
readonly observer: EventEmitter;
}

export default ({ service, observer }: FactoryConfig) => {
return (
<ConnectProvider service={service} observer={observer} render={() => {
Expand Down
29 changes: 1 addition & 28 deletions src/presenter/index.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,7 @@
import * as dom from 'react-dom';
import { State } from '../repo/FactoryConfig';
import observer from '../utils/observer';
import app from './app';

const initialState: State = {
editedTitles: {},
isEditing: {},
newTodoTitle: '',
route: '',
todos: [],
};

const getState = (): State => {
const localStorageState = window.localStorage.getItem('state');
if (localStorageState === null) {
return initialState;
}
return JSON.parse(localStorageState);
};

const patchState = (patch: Partial<State>) => {
const prevState = getState();
const nextState = { ...prevState, ...patch };
// tslint:disable-next-line:no-console
console.log('PATCH STATE', patch);
window.localStorage.setItem('state', JSON.stringify(nextState));
observer.emit('change', patch);
};

dom.render(
app({ repo: { getState, patchState } }),
app(),
document.getElementsByClassName('todoapp')[0],
);
14 changes: 0 additions & 14 deletions src/repo/Facade.ts

This file was deleted.

16 changes: 0 additions & 16 deletions src/repo/FactoryConfig.ts

This file was deleted.

41 changes: 35 additions & 6 deletions src/repo/factory.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,38 @@
import Facade from '@js-entity-repos/core/dist/Facade';
import memoryFactory from '@js-entity-repos/memory/dist/factory';
import Facade from './Facade';
import FactoryConfig from './FactoryConfig';
import TodoEntity from '../utils/TodoEntity';

export default ({ getState, patchState }: FactoryConfig): Facade => {
const todosFacade = memoryFactory({
export interface FactoryConfig {
readonly emitChange: () => void;
}

export default ({ emitChange }: FactoryConfig) => {
const initialState = {
editedTitles: {} as { readonly [id: string]: string },
isEditing: {} as { readonly [id: string]: boolean },
newTodoTitle: '' as string,
route: '' as string,
todos: [] as TodoEntity[],
};

const getState = (): typeof initialState => {
const localStorageState = window.localStorage.getItem('state');
if (localStorageState === null) {
return initialState;
}
return JSON.parse(localStorageState);
};

const patchState = (patch: Partial<typeof initialState>) => {
const prevState = getState();
const nextState = { ...prevState, ...patch };
// tslint:disable-next-line:no-console
console.log('PATCH STATE', patch);
window.localStorage.setItem('state', JSON.stringify(nextState));
emitChange();
};

const todosFacade: Facade<TodoEntity> = memoryFactory({
defaultPaginationLimit: 100,
entityName: 'Todo',
getEntities: () => getState().todos,
Expand All @@ -25,10 +54,10 @@ export default ({ getState, patchState }: FactoryConfig): Facade => {
isEditing: { ...getState().isEditing, [id]: isEditing },
});
},
setNewTodoTitle: (title) => {
setNewTodoTitle: (title: string) => {
patchState({ newTodoTitle: title });
},
setRoute: (route) => {
setRoute: (route: string) => {
patchState({ route });
},
todos: todosFacade,
Expand Down
20 changes: 0 additions & 20 deletions src/service/Facade.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/service/FactoryConfig.ts

This file was deleted.

32 changes: 19 additions & 13 deletions src/service/factory.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import Facade from './Facade';
import FactoryConfig from './FactoryConfig';
import Sort from '@js-entity-repos/core/dist/types/Sort';
import { desc } from '@js-entity-repos/core/dist/types/SortOrder';
import repoFactory from '../repo/factory';
import TodoEntity from '../utils/TodoEntity';

export default ({ repo }: FactoryConfig): Facade => {
export interface FactoryConfig {
readonly repo: ReturnType<typeof repoFactory>;
}

export default ({ repo }: FactoryConfig) => {
return {
changeNewTodoTitle: (title) => {
changeNewTodoTitle: (title: string) => {
repo.setNewTodoTitle(title);
},
createNewTodo: async () => {
Expand All @@ -27,15 +33,15 @@ export default ({ repo }: FactoryConfig): Facade => {
filter: { completed: true },
})).count;
},
getEditedTitle: (id) => {
getEditedTitle: (id: string) => {
return repo.getEditedTitle(id);
},
getIncompleteCount: async () => {
return (await repo.todos.countEntities({
filter: { completed: false },
})).count;
},
getIsEditing: (id) => {
getIsEditing: (id: string) => {
return repo.getIsEditing(id);
},
getNewTodoTitle: () => {
Expand All @@ -46,7 +52,7 @@ export default ({ repo }: FactoryConfig): Facade => {
},
getRouteTodos: async () => {
const route = repo.getRoute();
const sort = { createdAt: false };
const sort: Sort<TodoEntity> = { createdAt: desc };
if (route === 'active') {
return (await repo.todos.getEntities({ sort, filter: { completed: false } })).entities;
}
Expand All @@ -55,22 +61,22 @@ export default ({ repo }: FactoryConfig): Facade => {
}
return (await repo.todos.getEntities({ sort })).entities;
},
removeTodo: async (id) => {
removeTodo: async (id: string) => {
await repo.todos.removeEntity({ id });
},
setEditedTitle: (id, title) => {
setEditedTitle: (id: string, title: string) => {
repo.setEditedTitle(id, title);
},
setIsEditing: (id, isEditing) => {
setIsEditing: (id: string, isEditing: boolean) => {
repo.setIsEditing(id, isEditing);
},
setRoute: async (route) => {
setRoute: async (route: string) => {
repo.setRoute(route);
},
setTodoCompletion: async (id, completed) => {
setTodoCompletion: async (id: string, completed: boolean) => {
await repo.todos.patchEntity({ id, patch: { completed } });
},
setTodoTitle: async (id, title) => {
setTodoTitle: async (id: string, title: string) => {
await repo.todos.patchEntity({ id, patch: { id, title } });
},
};
Expand Down

0 comments on commit 44b5422

Please sign in to comment.