How to use the mobx.transaction 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 ksandin / darkestdungeon / src / screens / estate / Store.tsx View on Github external
componentWillUnmount () {
    // Return all items that has not been checked out
    transaction(() => {
      this.cart.slice().forEach((item) => this.returnItem(item));
    });
    this.stopManagingDebt();
  }
github ascoders / gaea-editor / gaea-editor / actions / viewport.ts View on Github external
@action('清空当前状态') clean() {
        transaction(() => {
            this.viewport.currentEditComponentMapUniqueKey = null
            this.viewport.currentHoverComponentMapUniqueKey = null
            this.viewport.currentDragComponentInfo = null
            this.viewport.showEditComponents = false
        })
    }
github meetalva / alva / packages / core / src / container / element-list / element-list.tsx View on Github external
private handleMouseOver(e: React.MouseEvent): void {
		const { store } = this.props as { store: Store.ViewStore };
		const targetElement = utils.elementFromTarget(e.target as HTMLElement, {
			sibling: false,
			store
		});

		const targetContent = utils.elementContentFromTarget(e.target, { store });
		const item = utils.above(e.target, `[${C.ElementAnchors.item}]`);

		const isElementMouseOver = item && targetElement;
		const isContentMouseOver = item && targetContent;
		const isRootMouseOver =
			!item && targetElement && targetElement.getRole() === Types.ElementRole.Root;

		Mobx.transaction(() => {
			if (isElementMouseOver || isContentMouseOver || isRootMouseOver) {
				store.getProject().unsetHighlightedElement();
				store.getProject().unsetHighlightedElementContent();
			}

			if (
				item &&
				targetElement &&
				targetContent === targetElement.getContentBySlotId(Types.SlotType.Children)
			) {
				targetElement.setHighlighted(true);
			}

			if (item && targetContent && targetContent.getSlotType() === Types.SlotType.Children) {
				targetContent.setHighlighted(true);
			}
github ascoders / gaea-editor / lib / gaea-editor / actions / viewport.js View on Github external
value: function horizontalMoveComponent(parentMapUniqueKey, beforeIndex, afterIndex) {
            var layoutChilds = this.viewport.components.get(parentMapUniqueKey).layoutChilds;
            if (beforeIndex < afterIndex) {
                mobx_1.transaction(function () {
                    for (var index = beforeIndex; index < afterIndex; index++) {
                        var beforeUniqueKey = layoutChilds[index];
                        var afterUniqueKey = layoutChilds[index + 1];
                        layoutChilds[index] = afterUniqueKey;
                        layoutChilds[index + 1] = beforeUniqueKey;
                    }
                });
            } else {
                mobx_1.transaction(function () {
                    for (var index = beforeIndex; index > afterIndex; index--) {
                        var beforeUniqueKey = layoutChilds[index];
                        var afterUniqueKey = layoutChilds[index - 1];
                        layoutChilds[index] = afterUniqueKey;
                        layoutChilds[index - 1] = beforeUniqueKey;
                    }
                });
            }
        }
    }, {
github meetalva / alva / packages / core / src / container / element-list / element-list.tsx View on Github external
e.preventDefault();
			return;
		}

		if (draggedElement.getNameEditable()) {
			e.preventDefault();
			return;
		}

		if (this.dragImg.current) {
			e.dataTransfer.effectAllowed = 'move';
			e.dataTransfer.setData('text', JSON.stringify(draggedElement.toJSON()));
			e.dataTransfer.setDragImage(this.dragImg.current, 75, 15);
		}

		Mobx.transaction(() => {
			draggedElement.setDragged(true);
			store.setSelectedElement(draggedElement);
		});
	}
github plotly / spectacle-editor / app / stores / slides-store.js View on Github external
incrementCurrentElementIndexBy(num) {
    const slidesArray = this.slides;
    const currentChildren = slidesArray[this.currentSlideIndex].children;

    if (
      !this.currentElement ||
      num + this.currentElementIndex < 0 ||
      num + this.currentElementIndex >= currentChildren.length
    ) {
      return;
    }

    transaction(() => {
      const currentChild = currentChildren[this.currentElementIndex];
      const sibling = currentChildren[this.currentElementIndex + num];
      const newParagraphStyles = this.paragraphStyles;

      currentChildren[this.currentElementIndex] = sibling;
      currentChildren[this.currentElementIndex + num] = currentChild;

      this._addToHistory({
        paragraphStyles: newParagraphStyles,
        currentSlideIndex: this.currentSlideIndex,
        currentElementIndex: this.currentElementIndex + num,
        slides: slidesArray
      });
    });
  }
github vinej / react-portal / src / stores / auth_store.js View on Github external
signOut() {
    localStorage.removeItem('react-portal-token');
    localStorage.removeItem('react-portal-name');
    transaction(() => {
      this.authenticated = false;
      this.name = '';
      this.errorMessage = '';
    });
    dispatch(tabbarCloseAll())
  }
github plotly / spectacle-editor / app / stores / slides-store.js View on Github external
setSelectedSlideIndex(newSlideIndex) {
    const snapshot = this.currentState;
    snapshot.currentElementIndex = null;
    snapshot.currentSlideIndex = newSlideIndex;

    transaction(() => {
      const left = this.history.slice(0, this.historyIndex);
      const right = this.history.slice(this.historyIndex + 1, this.history.length);
      this.history = left.concat([snapshot], right);
    });
  }
github plotly / spectacle-editor / app / stores / slides-store.js View on Github external
updateElementResizeState(isResizingElement, cursor = null) {
    transaction(() => {
      this.cursorType = cursor;
      this.isResizing = isResizingElement;
    });
  }
github microsoft / satcheljs / src / dispatcher.ts View on Github external
export function dispatch(actionMessage: ActionMessage) {
    if (getGlobalContext().inMutator) {
        throw new Error('Mutators cannot dispatch further actions.');
    }

    let dispatchWithMiddleware = getGlobalContext().dispatchWithMiddleware || finalDispatch;
    transaction(dispatchWithMiddleware.bind(null, actionMessage));
}