• Stars
    star
    107
  • Rank 323,587 (Top 7 %)
  • Language
    JavaScript
  • Created about 8 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Reduces `action` and `runInAction` boilerplates

babel-plugin-mobx-deep-action

Build Status npm version

Allow to reduce boilerplate of writing async actions. Based on assumption, that all code created inside an action, should be handled as action too.

This plugin scans for all functions, marked as actions, and then marks all nested functions, which created inside actions as actions too.

Example

In

import { action } from "mobx";

action(function doSome() {
  fetch("/api/list").then(function(response) {
    this.items = response.dta;
  });
});

Out

"use strict";

import { action } from "mobx";

action(function doSome() {
  fetch("/api/list").then(action(function(response) {
    this.items = response.dta;
  }));
});

Caveats

Plugin support only ES6 imports. Only these imports are supported:

import {action} from "mobx";
import {action as actionAlias} from "mobx";
import * as mobx from "mobx";
import * as mobxAlias from "mobx";

For example, these cases are not supported:

const mobx = require("mobx")
const {action} = require("mobx")
import * as mobx from "my-mobx-alias"
import * as mobx from "mobx";
const {action} = mobx;
action(function() {});

Installation

$ npm install babel-plugin-mobx-deep-action

Usage

Via .babelrc (Recommended)

.babelrc

{
  "plugins": ["mobx-deep-action"]
}

Via CLI

$ babel --plugins mobx-deep-action script.js

Via Node API

require("babel-core").transform("code", {
  plugins: ["mobx-deep-action"]
});

Usage for async and generator functions.

see https://github.com/Strate/babel-plugin-mobx-async-action

Typescript decorators.

This plugin could handle decorators code, emitted from typescript, such as:

import * as tslib_1 from "tslib";
import { action } from "mobx";
export default class Class2 {
    async method() {
        const a = (other) => { };
        return a(function () { });
    }
}
tslib_1.__decorate([
    action
], Class2.prototype, "method", null);

To get this code worked, you should enable importHelpers compiler option, and get tslib package installed. Also, typescript should emit es6 modules, so, you should target your compiler to es2015+. That's all, plugin detect import from "tslib" and handle typescript decorators.

Use other package.

If you use wrapper for "mobx" package, you can pass it's name to plugin:

.babelrc

{
  "plugins": [
    ["mobx-deep-action", {
      "mobx-package": "mobx-custom"
    }]
  ]
}

More Repositories

1

mobx

Simple, scalable state management.
TypeScript
27,520
star
2

mobx-state-tree

Full-featured reactive state management without the boilerplate
TypeScript
6,945
star
3

mobx-react

React bindings for MobX
TypeScript
4,856
star
4

mobx.dart

MobX for the Dart language. Hassle-free, reactive state-management for your Dart and Flutter apps.
Dart
2,397
star
5

awesome-mobx

A collection of awesome things regarding MobX.
2,189
star
6

mobx-react-lite

Lightweight React bindings for MobX based on React 16.8 and Hooks
TypeScript
2,129
star
7

mobx-react-devtools

[DEPRECATED] Tools to perform runtime analyses of React applications powered by MobX and React
JavaScript
1,229
star
8

mobx-utils

Utility functions and common patterns for MobX
TypeScript
1,184
star
9

mobx-react-boilerplate

Small project to quickly start with React, MobX, JSX, ES6, Babel
JavaScript
889
star
10

serializr

Serialize and deserialize complex object graphs to and from JSON and Javascript classes
TypeScript
766
star
11

mst-gql

Bindings for mobx-state-tree and GraphQL
JavaScript
682
star
12

mobx-react-todomvc

TodoMVC reference implementation on top of react-mobx-boilerplate
JavaScript
502
star
13

mobx-devtools

Mobx Devtools (React, Chrome Extension) - Looking for maintainers! https://github.com/mobxjs/mobx-devtools/issues/55
JavaScript
488
star
14

mobx-angular

The MobX connector for Angular.
TypeScript
482
star
15

mobx-vue

πŸ‰ Vue bindings for MobX
TypeScript
475
star
16

mobx-examples

A collection of simple mobx examples
HTML
284
star
17

create-react-app-mobx

DEPRECATED. Use https://github.com/arackaf/customize-cra
JavaScript
146
star
18

mobx-preact

MobX bindings for Preact
JavaScript
126
star
19

mobx-reactive2015-demo

Runnable source code of the #GoReactive #mobservable talk
JavaScript
98
star
20

mobx-contacts-list

React Amsterdam 2016 Demo Project
JavaScript
76
star
21

mobx-vue-lite

Lightweight Vue 3 bindings for MobX based on Composition API.
TypeScript
69
star
22

mobx-angularjs

MobX connector to AngularJS
TypeScript
51
star
23

mobx-react-docz

DEPRECATED Documentation site for MobX in React
TypeScript
42
star
24

zh.mobx.js.org

MobxδΈ­ζ–‡ζ–‡ζ‘£
HTML
40
star
25

ko.mobx.js.org

Mobx korean document
HTML
11
star
26

mobxjs.github.io

Redir to mobx documentation
HTML
1
star
27

.github

1
star
28

mst-codemod-to-0.10

A codemod to migrate to MobX-State-Tree 0.10 from previous versions
TypeScript
1
star