How to use the mobx.observable.box function in mobx

To help you get started, we’ve selected a few mobx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github IjzerenHein / firestorter / src / enhancedObservable.ts View on Github external
export function enhancedObservable(
	data: any,
	delegate: IEnhancedObservableDelegate
): any {
	const o = Array.isArray(data) ? observable.array(data) : observable.box(data);

	// Hook into the MobX observable and track
	// Whether any Component is observing this observable.
	const atom: any = getAtom(o);
	const onBecomeUnobserved = atom.onBecomeUnobserved;
	const reportObserved = atom.reportObserved;
	let isObserved = false;
	atom.isPendingUnobservation = false;
	atom.onBecomeUnobserved = () => {
		const res = onBecomeUnobserved.apply(atom, arguments);
		if (isObserved) {
			isObserved = false;
			delegate.releaseObserverRef();
		}
		return res;
	};
github sulu / sulu / src / Sulu / Bundle / AdminBundle / Resources / js / views / Form / Form.js View on Github external
resourceStore: ResourceStore,
    title?: string,
};

const FORM_STORE_UPDATE_ROUTE_HOOK_PRIORITY = 2048;

const HAS_CHANGED_ERROR_CODE = 1102;

@observer
class Form extends React.Component {
    resourceStore: ResourceStore;
    resourceFormStore: ResourceFormStore;
    collaborationStore: ?CollaborationStore;
    form: ?ElementRef;
    @observable errors: Array = [];
    showSuccess: IObservableValue = observable.box(false);
    @observable toolbarActions: Array = [];
    @observable showDirtyWarning: boolean = false;
    @observable showHasChangedWarning: boolean = false;
    postponedSaveOptions: Object;
    postponedUpdateRouteMethod: ?UpdateRouteMethod;
    postponedRoute: ?Route;
    postponedRouteAttributes: ?AttributeMap;
    checkFormStoreDirtyStateBeforeNavigationDisposer: () => void;

    @computed get hasOwnResourceStore() {
        const {resourceStore} = this.props;

        return this.resourceKey && resourceStore.resourceKey !== this.resourceKey;
    }

    @computed.struct get locales() {
github IjzerenHein / react-native-magic-move / examples / expo / src / explorer / ExplorerComponentStore.js View on Github external
shape,
    content,
    size,
    position,
    transition,
    duration,
    easing,
    disabled
  }) {
    this._label = label;
    this._content = observable.box(getByLabel(CONTENTS, content));
    this._size = observable.box(getByLabel(SIZES, size));
    this._shape = observable.box(getByLabel(SHAPES, shape));
    this._position = observable.box(getByLabel(POSITIONS, position));
    this._transition = observable.box(getByLabel(TRANSITIONS, transition));
    this._duration = observable.box(getByLabel(DURATIONS, duration));
    this._easing = observable.box(getByLabel(EASINGS, easing));
    this._disabled = observable.box(getByLabel(DISABLEDS, disabled));
  }
github rakannimer / react-firebase / modules / database / src / demo / app.tsx View on Github external
import {
  FirebaseDatabaseNode,
  FirebaseDatabaseProvider,
  FirebaseDatabaseNodes
} from "..";
import { FirebaseDatabaseMutation } from "../components/FirebaseDatabaseMutation";
import { FirebaseDatabaseTransaction } from "../components/FirebaseDatabaseTransaction";
import ReactJson from "react-json-view";
import { renderAndAddProps } from "render-and-add-props";
import { render } from "react-dom";
import { observable, IObservableValue } from "mobx";
import { observer } from "mobx-react";

export const formState = {
  path: observable.box("posts"),
  isList: observable.box(false),
  keysOnly: observable.box(false),
  limitToFirst: observable.box(2),
  limitToLast: observable.box(undefined),
  orderByChild: observable.box(undefined),
  orderByKey: observable.box(undefined),
  orderByValue: observable.box(undefined),
  startAt: observable.box(undefined),
  endAt: observable.box(undefined),
  equalTo: observable.box(undefined),
  once: observable.box(undefined)
};

const StringInput = observer(
  ({ obs, label = "" }: { obs: IObservableValue; label: string }) => {
    return (
      <div></div>
github WorldWindEarth / worldwind-react-app / src / components / Globe.js View on Github external
getCategoryTimestamp(category) {
        if (!this.categoryTimestamps.has(category)) {
            this.categoryTimestamps.set(category, observable.box(Date.now()));
        }
        return this.categoryTimestamps.get(category);
    }
github fox-finder / FoxFinder / src / bases / features / header / index.tsx View on Github external
import { observable, computed, IObservableValue, IComputedValue } from 'mobx';
import { observer } from 'mobx-react'
import { CSSTransition } from 'react-transition-group'
import { TRANSITION_DURATION_SLOW } from 'constants/animation'
import { option } from 'engines/option'
import { process } from 'engines/process'
import { Background } from 'bases/materials/background'
import { menuStore } from 'bases/features/menu';
import { DockFixedAppList, DockRunningAppList } from './dock';
import { Tray } from './Tray';
import { Launcher } from './Launcher';
import styles from './header.module.scss';

export const sortingIndex: IObservableValue = observable.box(null)
export const tippingIndex: IObservableValue = observable.box(null)
export const calendarOperating: IObservableValue = observable.box(false)
export const isSomeDockItemOperating: IComputedValue = computed(
  () =&gt; (sortingIndex.get() !== null) || (tippingIndex.get() !== null) || calendarOperating.get()
)
export const isDisabledTooltip: IComputedValue = computed(
  () =&gt; isSomeDockItemOperating.get() || menuStore.visible
)

export const Header: React.FC = observer(() =&gt; {
  return (
    <div id="header">
       event.preventDefault()}</div>
github dsifford / academic-bloggers-toolkit / src / js / _legacy / dialogs / pubmed / index.tsx View on Github external
errorMessage = observable.box('');

    /**
     * Controls the loading state of the dialog
     */
    isLoading = observable.box(false);

    /**
     * Current page of results
     */
    page = observable.box(0);

    /**
     * Controls the state of the input field
     */
    query = observable.box('');

    /**
     * Array of results returned from the pubmed search
     */
    results = observable([]);

    @computed
    get visibleResults(): CSL.Data[] {
        const end = this.page.get() * 5;
        const start = end - 6;
        return this.results.filter((_result, i) =&gt; {
            return start &lt; i &amp;&amp; i &lt; end;
        });
    }

    @action
github sulu / sulu / src / Sulu / Bundle / AdminBundle / Resources / js / views / ResourceTabs / ResourceTabs.js View on Github external
id,
            },
        } = router;
        const {
            options: {
                resourceKey,
            },
        } = route;

        if (!resourceKey) {
            throw new Error('The route does not define the mandatory "resourceKey" option');
        }

        const options = {};
        if (this.locales) {
            options.locale = observable.box();
            router.bind('locale', options.locale);
        }

        if (id !== undefined && typeof id !== 'string' && typeof id !== 'number') {
            throw new Error('The "id" router attribute must be a string or a number if given!');
        }

        this.resourceStore = new ResourceStore(resourceKey, id, options);

        this.reloadResourceStoreOnRouteChangeDisposer = router.addUpdateRouteHook(
            this.reloadResourceStoreOnRouteChange
        );
    }
github krausest / js-framework-benchmark / frameworks / keyed / mobx-jsx / src / main.jsx View on Github external
selectRow(rows) {
    let tr;
    const b = observable.box();
    autorun(() => b.set(rows()));
    autorun(() => {
      const s = this.selected;
      if (tr) tr.className = '';
      if (tr = s && b.get().find(tr => tr.model === s)) tr.className = 'danger';
    });
    return () => b.get();
  }