-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial refactor of todo-mvc-kitchensink #190
Merged
Merged
Changes from 29 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
ac961f2
Starting to move over to classes
rorticus fd3ffb3
More updates
rorticus a4452f5
Getting it all together
rorticus b5c52d0
Setting the right widget-core version
rorticus fbb3c6f
Misc fixes
rorticus 8d1579c
Updating package classes
rorticus 99360a2
Updating to latest widget-core, converting to use class based routes
rorticus 32f9c79
Adding conditional to not error during tests
rorticus a505222
Converting to CSS
rorticus df7560d
More CSS styles
rorticus bbb8762
More CSS
rorticus 00377f7
Removing css.d.ts
rorticus 16bd2f4
Removing more unused styles
rorticus bcee354
WIP
rorticus ed0d7d7
WIP
rorticus 1cd2bbc
WIP
rorticus 369a5c2
More class conversions
rorticus b60c950
Adding i18n
rorticus 1feb945
More i18n
rorticus bdabc7d
Enough i18n for now..
rorticus 9366148
Adding a widget that using dojo/core/request
rorticus f9fe3ef
Making github issues a custom element
rorticus eb31ada
Starting to add theme
rorticus 5f3132c
Adding theming
rorticus 666391b
Adding pirate theme
rorticus ab63a9b
Fixing style errors
rorticus 27e290f
Updating css
rorticus 7f896ca
Updating tests
rorticus d5eb64a
Fixing infinite github bug
rorticus 41b30a8
Updating styles
rorticus 508567f
Renaming file
rorticus 7819297
Removing to rename files
rorticus b63cb74
More renaming files..
rorticus 9f40127
Code review feedback
rorticus 07c64c2
Removing wrong cased file
rorticus f8d7cf6
Renaming file for proper casing
rorticus 81ad8f1
Making custom elements shims external
rorticus 7c85feb
Removing custom element
rorticus ddaa025
Conditionally loading custom element, fixing FF tests
rorticus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,96 @@ | ||
import { deepAssign } from '@dojo/core/lang'; | ||
import { v, w } from '@dojo/widget-core/d'; | ||
import { DNode } from '@dojo/widget-core/interfaces'; | ||
import { I18nProperties, I18nMixin } from '@dojo/widget-core/mixins/I18n'; | ||
import { theme, ThemeableMixin, ThemeableProperties } from '@dojo/widget-core/mixins/Themeable'; | ||
import { WidgetBase } from '@dojo/widget-core/WidgetBase'; | ||
import * as styles from './widgets/styles/App.css'; | ||
import pirateThemeStyles from './themes/pirate'; | ||
import { AppFooter } from './widgets/AppFooter'; | ||
import Home from './widgets/Home'; | ||
import { ThemeSwitcher } from './widgets/ThemeSwitcher'; | ||
import TodoDetails from './widgets/TodoDetails'; | ||
|
||
interface AppProperties extends ThemeableProperties, I18nProperties { | ||
widgets?: any; | ||
todos?: Item[]; | ||
todo?: string; | ||
activeFilter?: string; | ||
activeView?: string; | ||
search?: string; | ||
todoDetails?: Item; | ||
pirateTheme?: boolean; | ||
} | ||
|
||
export interface Item { | ||
id: string; | ||
label?: string; | ||
completed?: boolean; | ||
createdOn?: Date; | ||
editing: boolean; | ||
} | ||
|
||
function createWidget(widgetName: string, widgetProperties: any): DNode { | ||
switch (widgetName) { | ||
case 'main': | ||
return w(Home, widgetProperties); | ||
case 'todo-details': | ||
return w(TodoDetails, widgetProperties); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
let app: App = <any> null; | ||
|
||
@theme(styles) | ||
export class App extends I18nMixin(ThemeableMixin(WidgetBase))<AppProperties> { | ||
constructor() { | ||
super(); | ||
|
||
app = this; | ||
this.applyTheme(); | ||
} | ||
|
||
applyTheme() { | ||
this.setProperties(deepAssign({}, this.properties, { | ||
theme: this.properties.pirateTheme ? pirateThemeStyles : undefined | ||
})); | ||
} | ||
|
||
changeTheme(wantsPirate: boolean) { | ||
this.setProperties(deepAssign({}, this.properties, { | ||
pirateTheme: wantsPirate | ||
})); | ||
|
||
this.applyTheme(); | ||
} | ||
|
||
render() { | ||
const { widgets = [ [ 'main', {} ] ], pirateTheme = false } = this.properties; | ||
|
||
return v('div', {}, [ | ||
v('section', { | ||
classes: this.classes(styles.todoapp).get() | ||
}, [ | ||
w(ThemeSwitcher, { | ||
theme: this.properties.theme, | ||
wantsPirate: pirateTheme, | ||
onChange: this.changeTheme | ||
}) | ||
].concat(widgets.map((widget: any) => { | ||
return createWidget(widget[ 0 ], <any> { | ||
...this.properties, ...widget[ 1 ], | ||
id: <string> widget[ 0 ] | ||
}); | ||
}))), | ||
w(AppFooter, { | ||
theme: this.properties.theme | ||
}) | ||
]); | ||
} | ||
} | ||
|
||
export default function () { | ||
return app; | ||
}; |
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,33 +1,56 @@ | ||
import todoStore, { Item } from '../stores/todoStore'; | ||
import createFilter from '@dojo/stores/query/createFilter'; | ||
import { assign } from '@dojo/core/lang'; | ||
import { deepAssign } from '@dojo/core/lang'; | ||
import app, { Item } from '../App'; | ||
|
||
let id = 0; | ||
|
||
export const addTodo = function({ label, completed }: { label: string, completed: boolean }) { | ||
return todoStore.add({ id: `${id++}`, label, completed, createdOn: new Date(), editing: false }); | ||
export const addTodo = function ({ label, completed }: { label: string, completed: boolean }) { | ||
const { todos = [] } = app().properties; | ||
|
||
todos.push({ id: `${id++}`, label, completed, createdOn: new Date(), editing: false }); | ||
|
||
app().setProperties(deepAssign({}, app().properties, { todos })); | ||
}; | ||
|
||
export const deleteTodo = function({ id }: { id: string }) { | ||
return todoStore.delete(id); | ||
export const deleteTodo = function ({ id }: { id: string }) { | ||
const { todos = [] } = app().properties; | ||
|
||
app().setProperties(deepAssign({}, app().properties, { | ||
todos: todos.filter((todo: Item) => { | ||
return todo.id !== id; | ||
}) | ||
})); | ||
}; | ||
|
||
export const deleteCompleted = function() { | ||
return todoStore.fetch(createFilter<Item>().equalTo('completed', true)) | ||
.then((items: Item[]) => todoStore.identify(items)) | ||
.then((ids: string[]) => todoStore.delete(ids)); | ||
export const deleteCompleted = function () { | ||
const { todos = [] } = app().properties; | ||
|
||
app().setProperties(deepAssign({}, app().properties, { | ||
todos: todos.filter((todo: Item) => { | ||
return todo.completed !== true; | ||
}) | ||
})); | ||
}; | ||
|
||
export const toggleAll = function({ checked: completed }: { checked: boolean }) { | ||
return todoStore.fetch() | ||
.then((items: Item[]) => { | ||
return items.map((item) => { | ||
return assign({}, item, <any> { completed }); | ||
}); | ||
export const toggleAll = function ({ checked: completed }: { checked: boolean }) { | ||
const { todos = [] } = app().properties; | ||
|
||
app().setProperties(deepAssign({}, app().properties, { | ||
todos: todos.map((item: Item) => { | ||
return deepAssign({}, item, <any> { completed }); | ||
}) | ||
.then((items) => todoStore.patch(items)); | ||
})); | ||
}; | ||
|
||
export const updateTodo = function(item: Item) { | ||
return todoStore.patch(item); | ||
export const updateTodo = function (item: Item) { | ||
const { todos = [] } = app().properties; | ||
|
||
app().setProperties(deepAssign({}, app().properties, { | ||
todos: todos.map((todo: Item) => { | ||
if (todo.id === item.id) { | ||
return deepAssign({}, todo, item); | ||
} | ||
|
||
return todo; | ||
}) | ||
})); | ||
}; |
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,8 +1,7 @@ | ||
import { assign } from '@dojo/core/lang'; | ||
import widgetStore from '../stores/widgetStore'; | ||
import { addTodo, deleteCompleted, deleteTodo, toggleAll, updateTodo } from './todoStoreActions'; | ||
import { deepAssign } from '@dojo/core/lang'; | ||
import app, { Item } from '../App'; | ||
import router, { todoViewRoute } from '../routes'; | ||
import { Item } from '../stores/todoStore'; | ||
import { addTodo, deleteCompleted, deleteTodo, toggleAll, updateTodo } from './todoStoreActions'; | ||
|
||
interface FormEvent extends Event { | ||
target: HTMLInputElement; | ||
|
@@ -12,11 +11,19 @@ interface FormInputEvent extends KeyboardEvent { | |
target: HTMLInputElement; | ||
} | ||
|
||
/* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. commented out code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deleted |
||
const completedCount = afterAll.filter(({ completed }) => completed).length; | ||
const activeCount = afterAll.length - completedCount; | ||
const allCompleted = afterAll.length === completedCount; | ||
*/ | ||
|
||
export const todoInput = function (this: any, { which, target: { value: label } }: FormInputEvent) { | ||
if (which === 13 && label) { | ||
addTodo({ label, completed: false }); | ||
widgetStore.patch({ id: 'todo-app', todo: '' }); | ||
this.invalidate(); | ||
|
||
app().setProperties(deepAssign({}, app().properties, { | ||
todo: '' | ||
})); | ||
} | ||
}; | ||
|
||
|
@@ -30,47 +37,45 @@ function toggleEditing(todos: Item[], todoId: string, editing: boolean): Item[] | |
} | ||
|
||
export const todoEdit = function (this: any, event: KeyboardEvent) { | ||
const { state: { id } } = this; | ||
const { properties: { todoId } } = this; | ||
if (event.type === 'keypress' && event.which !== 13 && event.which !== 32) { | ||
return; | ||
} | ||
widgetStore.get('todo-app').then((todoListState: any) => { | ||
const link = router.link(todoViewRoute, { | ||
filter: todoListState.activeFilter, | ||
view: todoListState.activeView, | ||
todoId: id | ||
}); | ||
document.location.href = link; | ||
|
||
const link = router.link(todoViewRoute, { | ||
filter: app().properties.activeFilter, | ||
view: app().properties.activeView, | ||
todoId | ||
}); | ||
|
||
document.location.href = link; | ||
}; | ||
|
||
export const todoEditInput = function (this: any, event: FormInputEvent) { | ||
const { state } = this; | ||
const { properties } = this; | ||
if (event.which === 13) { | ||
todoSave.call(this, event); | ||
} | ||
else if (event.which === 27) { | ||
widgetStore.get('todo-app').then((todoListState: any) => { | ||
const { todos } = todoListState; | ||
todoListState.todos = toggleEditing(todos, state.id, false); | ||
widgetStore.patch({ id: 'todo-app', todoListState }); | ||
}); | ||
app().setProperties(deepAssign({}, app().properties, { | ||
todos: toggleEditing(app().properties.todos || [], properties.id, false) | ||
})); | ||
} | ||
}; | ||
|
||
export const todoSave = function (this: any, event: FormInputEvent) { | ||
const { state } = this; | ||
const { properties } = this; | ||
if (!event.target.value) { | ||
deleteTodo(state); | ||
deleteTodo(properties); | ||
} | ||
else { | ||
updateTodo(assign(state, { label: event.target.value, editing: false })); | ||
updateTodo(deepAssign({}, properties, { label: event.target.value, editing: false })); | ||
} | ||
}; | ||
|
||
export const todoRemove = function (this: any) { | ||
const { state } = this; | ||
deleteTodo({ id: state.id }); | ||
const { properties } = this; | ||
deleteTodo({ id: properties.todoId }); | ||
}; | ||
|
||
export const todoToggleComplete = function (this: any) { | ||
|
@@ -87,9 +92,7 @@ export const clearCompleted = function () { | |
}; | ||
|
||
export const updateSearch = function (this: any, searchQuery: string) { | ||
widgetStore.get('todo-app').then((todoListState: any) => { | ||
todoListState.search = searchQuery; | ||
|
||
widgetStore.patch({ id: 'todo-app', todoListState }); | ||
}); | ||
app().setProperties(deepAssign({}, app().properties, { | ||
search: searchQuery | ||
})); | ||
}; |
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,29 +1,34 @@ | ||
import { StoreDelta } from '@dojo/stores/store/mixins/createObservableStoreMixin'; | ||
import widgetStore from '../stores/widgetStore'; | ||
import todoStore from '../stores/todoStore'; | ||
import { Item } from '../stores/todoStore'; | ||
|
||
export const putTodo = function({ afterAll = [] }: StoreDelta<any>) { | ||
const completedCount = afterAll.filter(({ completed }) => completed).length; | ||
const activeCount = afterAll.length - completedCount; | ||
const allCompleted = afterAll.length === completedCount; | ||
|
||
return widgetStore.patch({ id: 'todo-app', todos: afterAll, activeCount, completedCount, allCompleted }); | ||
}; | ||
import { deepAssign } from '@dojo/core/lang'; | ||
import app, { Item } from '../App'; | ||
|
||
export const setHierarchy = function (this: any, widgets: [ string, any ][]) { | ||
widgetStore.patch({ id: 'todo-app', widgets }); | ||
app().setProperties(deepAssign({}, app().properties, { | ||
widgets | ||
})); | ||
}; | ||
|
||
export const filterAndView = function (this: any, filter: 'active' | 'all' | 'completed', view: 'list' | 'cards') { | ||
const { state: { activeView = view, activeFilter = filter } = { } } = this; | ||
widgetStore.patch({ id: 'todo-app', activeView, activeFilter }); | ||
const { state: { activeView = view, activeFilter = filter } = {} } = this; | ||
|
||
app().setProperties(deepAssign({}, app().properties, { | ||
activeView, activeFilter | ||
})); | ||
}; | ||
|
||
export const showTodoDetails = function(todoId: string) { | ||
return todoStore.get(todoId).then(( todo: Item) => { | ||
widgetStore.patch({ id: 'todo-details', todoDetails: todo }).then(() => { | ||
setHierarchy([ [ 'main', {} ], [ 'todo-details', { id: 'todo-details', externalState: widgetStore } ] ]); | ||
}); | ||
export const showTodoDetails = function (todoId: string) { | ||
let details: Item | null = null; | ||
|
||
(app().properties.todos || []).forEach((todo) => { | ||
if (todo.id === todoId) { | ||
details = todo; | ||
} | ||
}); | ||
|
||
if (details !== null) { | ||
app().setProperties(deepAssign({}, app().properties, { | ||
todoDetails: details | ||
})); | ||
|
||
setHierarchy([ [ 'main', {} ], [ 'todo-details', { id: 'todo-details' } ] ]); | ||
} | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you bump this to
2.4.3
please?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bumped!