aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/DocComponent.tsx
blob: 6d51122d41a197bfd69e6a1cea6676f81f528057 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import * as React from 'react';
import { Doc } from '../../new_fields/Doc';
import { computed } from 'mobx';
import { Touchable } from './Touchable';

export function DocComponent<P extends { Document: Doc }, T>(schemaCtor: (doc: Doc) => T) {
    class Component extends Touchable<P> {
        //TODO This might be pretty inefficient if doc isn't observed, because computed doesn't cache then
        @computed
        get Document(): T {
            return schemaCtor(this.props.Document);
        }
    }
    return Component;
}