Skip to content

Instantly share code, notes, and snippets.

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> {
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);
import { TodoService } from "./todoService";
export const todoService = new TodoService();
import { Observable } from "./observable";
export interface Todo {
readonly text: string;
readonly completed: boolean;
}
export enum VisibilityFilter {
SHOW_ALL,
SHOW_COMPLETED,
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]);
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;
const initialState = {
visibilityFilter: VisibilityFilters.SHOW_ALL,
todos: []
}
function todos(state = [], action) {
switch (action.type) {
case ADD_TODO:
return [
...state,
"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"
}
}
}
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 () => {
@simontreny
simontreny / App.tsx
Last active March 11, 2019 13:31
Ajout de vues animées lors du défilement
renderHeader() {
const { scrollOffset } = this.state;
const expandedHeaderHeight = 240;
const collapsedHeaderHeight = 64;
const titleHeight = 44;
const scrollSpan = expandedHeaderHeight - collapsedHeaderHeight;
return (
<Animated.View
style={{