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 { ReadableSignal, Signal } from "micro-signals"; | |
| export interface ReadableObservable<T> { | |
| onChange: ReadableSignal<T>; | |
| get(): T; | |
| map<U>(transform: (val: T) => U): ReadableObservable<U>; | |
| filter(predicate: (val: T) => boolean): ReadableObservable<T | undefined>; | |
| } | |
| abstract class BaseObservable<T> implements ReadableObservable<T> { |
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 React from "react"; | |
| import { useObservable } from "./observableHook"; | |
| import { todoService } from "./services"; | |
| import { Todo, VisibilityFilter } from "./todoService"; | |
| export const TodoList = () => { | |
| const todos = useObservable(todoService.todos); | |
| const filter = useObservable(todoService.visibilityFilter); | |
| const visibleTodos = getVisibleTodos(todos, filter); |
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 { TodoService } from "./todoService"; | |
| export const todoService = new TodoService(); |
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 { Observable } from "./observable"; | |
| export interface Todo { | |
| readonly text: string; | |
| readonly completed: boolean; | |
| } | |
| export enum VisibilityFilter { | |
| SHOW_ALL, | |
| SHOW_COMPLETED, |
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 { useEffect, useState } from "react"; | |
| import { Observable } from "./observable"; | |
| export function useObservable<T>(observable: Observable<T>): T { | |
| const [val, setVal] = useState(observable.get()); | |
| useEffect(() => { | |
| return observable.subscribe(setVal); | |
| }, [observable]); |
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
| type Listener<T> = (val: T) => void; | |
| type Unsubscriber = () => void; | |
| export class Observable<T> { | |
| private _listeners: Listener<T>[] = []; | |
| constructor(private _val: T) {} | |
| get(): T { | |
| return this._val; |
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
| const initialState = { | |
| visibilityFilter: VisibilityFilters.SHOW_ALL, | |
| todos: [] | |
| } | |
| function todos(state = [], action) { | |
| switch (action.type) { | |
| case ADD_TODO: | |
| return [ | |
| ...state, |
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
| "detox": { | |
| "configurations": { | |
| "ios.sim.debug": { | |
| "binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/MonApp.app", | |
| "build": "xcodebuild -project ios/MonApp.xcodeproj -scheme example -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build", | |
| "type": "ios.simulator", | |
| "name": "iPhone 7" | |
| } | |
| } | |
| } |
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('Example', () => { | |
| beforeEach(async () => { | |
| await device.reloadReactNative(); | |
| }); | |
| it('should have welcome text', async () => { | |
| await expect(element(by.id('welcomeText'))).toBeVisible(); | |
| }); | |
| it('should show hello screen after tap', async () => { |
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
| renderHeader() { | |
| const { scrollOffset } = this.state; | |
| const expandedHeaderHeight = 240; | |
| const collapsedHeaderHeight = 64; | |
| const titleHeight = 44; | |
| const scrollSpan = expandedHeaderHeight - collapsedHeaderHeight; | |
| return ( | |
| <Animated.View | |
| style={{ |
NewerOlder