blob: bb7a07f0e4d94b2d172ab9e91b61b7c564d4f26d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
import { action, makeObservable, observable } from 'mobx';
import * as React from 'react';
import './AntimodeMenu.scss';
import { observer } from 'mobx-react';
import JsxParser from 'react-jsx-parser';
/**
* This is an abstract class that serves as the base for a PDF-style or Marquee-style
* menu. To use this class, look at PDFMenu.tsx or MarqueeOptionsMenu.tsx for an example.
*/
export abstract class ObservableReactComponent<T> extends React.Component<T, object> {
@observable _props: React.PropsWithChildren<T>;
constructor(props: React.PropsWithChildren<T>) {
super(props);
this._props = props;
makeObservable(this);
}
componentDidUpdate(prevProps: Readonly<T>): void {
Object.keys(prevProps)
.filter(pkey => (prevProps as {[key:string]: unknown})[pkey] !== (this.props as {[key:string]: unknown})[pkey])
.forEach(action(pkey => {
(this._props as {[key:string]: unknown})[pkey] = (this.props as {[key:string]: unknown})[pkey];
})); // prettier-ignore
}
}
class ObserverJsxParser1 extends JsxParser {
constructor(props: object) {
super(props);
observer(this as typeof JsxParser);
}
}
export const ObserverJsxParser = ObserverJsxParser1 as typeof JsxParser;
|