Convertir to typescript
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
import Store from '.';
|
||||
|
||||
export const setMenuOpen = open => {
|
||||
Store.update(s => {
|
||||
s.menuOpen = open;
|
||||
});
|
||||
};
|
||||
|
||||
export const setNotificationsOpen = open => {
|
||||
Store.update(s => {
|
||||
s.notificationsOpen = open;
|
||||
});
|
||||
};
|
||||
|
||||
export const setSettings = settings => {
|
||||
Store.update(s => {
|
||||
s.settings = settings;
|
||||
});
|
||||
};
|
||||
|
||||
// App-specific actions
|
||||
|
||||
export const setDone = (list, item, done) => {
|
||||
Store.update((s, o) => {
|
||||
const listIndex = o.lists.findIndex(l => l === list);
|
||||
const itemIndex = o.lists[listIndex].items.findIndex(i => i === item);
|
||||
s.lists[listIndex].items[itemIndex].done = done;
|
||||
if (list === o.selectedList) {
|
||||
s.selectedList = s.lists[listIndex];
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
import Store from '.';
|
||||
import { ListItem, Settings, TodoListItem } from '../mock';
|
||||
|
||||
export const setMenuOpen = (open: boolean) => {
|
||||
Store.update(s => {
|
||||
s.menuOpen = open;
|
||||
});
|
||||
};
|
||||
|
||||
export const setNotificationsOpen = (open: boolean) => {
|
||||
Store.update(s => {
|
||||
s.notificationsOpen = open;
|
||||
});
|
||||
};
|
||||
|
||||
export const setSettings = (settings: Settings) => {
|
||||
Store.update(s => {
|
||||
s.settings = settings;
|
||||
});
|
||||
};
|
||||
|
||||
// App-specific actions
|
||||
|
||||
export const setDone = (list: TodoListItem, item: ListItem, done: boolean) => {
|
||||
Store.update((s, o) => {
|
||||
const listIndex = o.lists.findIndex(l => l === list);
|
||||
const items = o.lists[listIndex].items;
|
||||
if(!items) return;
|
||||
const itemIndex = items.findIndex(i => i === item);
|
||||
const item = items[itemIndex];
|
||||
item.done = done;
|
||||
if (list === o.selectedList) {
|
||||
s.selectedList = s.lists[listIndex];
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -1,19 +0,0 @@
|
||||
import { Store as PullStateStore } from 'pullstate';
|
||||
|
||||
import { lists, homeItems, notifications } from '../mock';
|
||||
|
||||
const Store = new PullStateStore({
|
||||
safeAreaTop: 0,
|
||||
safeAreaBottom: 0,
|
||||
menuOpen: false,
|
||||
notificationsOpen: false,
|
||||
currentPage: null,
|
||||
homeItems,
|
||||
lists,
|
||||
notifications,
|
||||
settings: {
|
||||
enableNotifications: true,
|
||||
},
|
||||
});
|
||||
|
||||
export default Store;
|
||||
@@ -0,0 +1,31 @@
|
||||
import { Store as PullStateStore } from 'pullstate';
|
||||
|
||||
import { lists, homeItems, notifications, settings, TodoListItem, HomeItem, NotificationItem, Settings } from '../mock';
|
||||
|
||||
type StoreProps = {
|
||||
safeAreaTop: number;
|
||||
safeAreaBottom: number;
|
||||
menuOpen: boolean;
|
||||
notificationsOpen: boolean;
|
||||
currentPage: number | null;
|
||||
homeItems: HomeItem[];
|
||||
lists: TodoListItem[];
|
||||
notifications: NotificationItem[];
|
||||
settings: Settings;
|
||||
selectedList: TodoListItem | undefined;
|
||||
}
|
||||
|
||||
const Store = new PullStateStore<StoreProps>({
|
||||
safeAreaTop: 0,
|
||||
safeAreaBottom: 0,
|
||||
menuOpen: false,
|
||||
notificationsOpen: false,
|
||||
currentPage: null,
|
||||
homeItems,
|
||||
lists,
|
||||
notifications,
|
||||
settings,
|
||||
selectedList: undefined,
|
||||
});
|
||||
|
||||
export default Store;
|
||||
@@ -1,8 +0,0 @@
|
||||
import { createSelector } from 'reselect';
|
||||
|
||||
const getState = state => state;
|
||||
|
||||
export const getHomeItems = createSelector(getState, state => state.homeItems);
|
||||
export const getLists = createSelector(getState, state => state.lists);
|
||||
export const getNotifications = createSelector(getState, state => state.notifications);
|
||||
export const getSettings = createSelector(getState, state => state.settings);
|
||||
@@ -0,0 +1,39 @@
|
||||
import { createSelector } from 'reselect';
|
||||
import { HomeItem, NotificationItem, Settings, TodoListItem } from '../mock';
|
||||
|
||||
export interface RootState {
|
||||
homeItems: HomeItem[]
|
||||
lists: TodoListItem[]
|
||||
notifications: NotificationItem[]
|
||||
settings: Settings
|
||||
}
|
||||
|
||||
export const createAppSelector = createSelector.withTypes<RootState>()
|
||||
|
||||
export const selectHomeItems = createAppSelector(
|
||||
[
|
||||
state => state.homeItems
|
||||
],
|
||||
homeItems => homeItems
|
||||
)
|
||||
|
||||
export const selectLists = createAppSelector(
|
||||
[
|
||||
state => state.lists
|
||||
],
|
||||
lists => lists
|
||||
)
|
||||
|
||||
export const selectNotifications = createAppSelector(
|
||||
[
|
||||
state => state.notifications
|
||||
],
|
||||
notifications => notifications
|
||||
)
|
||||
|
||||
export const selectSettings = createAppSelector(
|
||||
[
|
||||
state => state.settings
|
||||
],
|
||||
settings => settings
|
||||
)
|
||||
Reference in New Issue
Block a user