This file contains hidden or 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
| describe('Notifications Store', () => { | |
| it('should have read and unread notifications', () => { | |
| const readNotification = new Notification('1', 'read', 100, true); | |
| const unreadNotification = new Notification('2', 'unread', 101, false); | |
| const unreadNotification2 = new Notification('3', 'unread2', 102, false); | |
| const notifications = [readNotification, unreadNotification, unreadNotification2]; | |
| const notificationsStore = NotificationsStore.initialize(notifications); | |
| expect(notificationsStore.unreadNotifications).to.have.length(2); |
This file contains hidden or 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
| describe('NotificationsViewContainer', () => { | |
| it('should render NotificationsView', () => { | |
| const readNotification = new Notification('1', 'read', 100, true); | |
| const unreadNotification = new Notification('2', 'unread', 101, false); | |
| const unreadNotification2 = new Notification('3', 'unread2', 102, false); | |
| const notifications = [readNotification, unreadNotification, unreadNotification2]; | |
| const notificationsStore = NotificationsStore.initialize(notifications); | |
| const wrapper = mount( | |
| <NotificationsViewContainer |
This file contains hidden or 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
| interface NotificationsViewProps { | |
| unreadNotifications: Notification[]; | |
| readNotifications: Notification[]; | |
| onMarkAsRead: (notification: Notification) => void; | |
| } | |
| class NotificationsView extends React.Component<NotificationsViewProps, {}> { | |
| render(): JSX.Element { | |
| return ( | |
| <div> |
This file contains hidden or 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
| interface NotificationsViewContainerProps { | |
| notificationsStore: NotificationsStore; | |
| } | |
| @observer | |
| class NotificationsViewContainer extends React.Component<NotificationsViewContainerProps, {}> { | |
| render(): JSX.Element { | |
| return ( | |
| <NotificationsView | |
| readNotifications={ this.props.notificationsStore.readNotifications } |
This file contains hidden or 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
| class RootStore { | |
| notificationsStore: NotificationsStore; | |
| initialize(): void { | |
| // Retrieve initial state of notifications | |
| const notifications: Notification[] = ... | |
| this.notificationsStore = NotificationsStore.initialize(notifications); | |
| } | |
| } |
This file contains hidden or 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
| class NotificationsStore { | |
| @observable notificationsById: mobx.ObservableMap<Notification>; | |
| static initialize(notifications: Notification[]): NotificationsStore { | |
| const notificationsById = mobx.asMap(_.keyBy(notifications, 'id')); | |
| return new NotificationsStore(notificationsById); | |
| } | |
| @computed get unreadNotifications(): Notification[] { | |
| return _(this.notificationsById.values()) |
This file contains hidden or 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
| class Notification { | |
| @observable read: boolean; | |
| constructor( | |
| public id: string, | |
| public content: string, | |
| public time: number, | |
| read: boolean | |
| ) { | |
| this.read = read; |
This file contains hidden or 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
| import math | |
| import random | |
| def get_random_neighbour(state): | |
| neighbour = [house[:] for house in state] # Deep copy | |
| i, j = random.sample(xrange(5), 2) | |
| attr_idx = random.randint(0, 4) | |
| neighbour[i][attr_idx], neighbour[j][attr_idx] = neighbour[j][attr_idx], neighbour[i][attr_idx] |