Giter VIP home page Giter VIP logo

mobx-sync's Introduction

mobx-sync

FOSSA Status

A library use JSON to persist your MobX stores with version control.

Features

  • use JSON.stringify/JSON.parse as the deserialize/serialize method
  • version control by using @version decorator
  • ignore any store node by using @ignore decorator
  • support React Native
  • support server side rendering (SSR)

Install

# by yarn
yarn add mobx-sync

# OR by npm
npm i -S mobx-sync

Quick Start

import { AsyncTrunk, date } from 'mobx-sync';
import { observable } from 'mobx';

class Store {
  @observable
  foo = 'bar';

  @date
  @observable
  date = new Date();
}

const store = new Store();

// create a mobx-sync instance, it will:
// 1. load your state from localStorage & ssr rendered state
// 2. persist your store to localStorage automatically
// NOTE: you do not need to call `trunk.updateStore` to persist
// your store, it is persisted automatically!
const trunk = new AsyncTrunk(store, { storage: localStorage });

// init the state and auto persist watcher(use MobX's autorun)
// NOTE: it will load the persisted state first(and must), and
// then load the state from ssr, if you pass it as the first
// argument of `init`, just like trunk.init(__INITIAL_STATE__)
trunk.init().then(() => {
  // you can do any staff now, just like:

  // 1. render app with initial state:
  ReactDOM.render(<App store={store} />);

  // 2. update store, the update of the store will be persisted
  // automatically:
  store.foo = 'foo bar';
});

Full Example

You can see it at example

API Reference

version control

Sometimes, if your store's data structure has been changed, which means the persisted data is illegal to use, you can use @version decorator to mark the store node with a version, if the persisted version is different from the declared node's version, the persisted version will be ignored.

For example, we publish an application like the Quick Start at first, and then we want to change the type of Store#foo from string to number. The persisted string value of foo thus become illegal, and should be ignored. It is necessary to use @version to mark the foo field with a new version to omit it:

import { version } from 'mobx-sync';
import { observable } from 'mobx';

class Store {
  @version(1)
  @observable
  foo = 1;

  @date
  @observable
  date = new Date();
}

// ...

When application with the new version is executed, the persisted value of foo will be ignored, while date keeps the persisted value. It means, after calling trunk.init(),the foo becomes 1, and date still stores the previous value.

NOTE: if the new version is strictly different with the persisted version, it will be ignored, or else it will be loaded as normal, so if you use it, we recommend you use an progressive increasing integer to mark it, because you couldn't know the version of persisted in client.

@version also supports class decorator, that means any instance of the class will be ignored if its version is different. For example:

import { version } from 'mobx-sync';
import { observable } from 'mobx';

@version(1)
class C1 {
  p1 = 1;
}

class C2 {
  p2 = 2;
}

class Store {
  c1 = new C1();
  c2 = new C2();
  c1_1 = new C1();
}

If the persisted version of store's c1 && c1_1 has different version with 1, they will be ignored.

NOTE: if you use a non-pure object as the store field, you must initialize it before you call trunk.init, just like custom store class(C1, C2 upon), observable.map, observable.array, etc. And it must be iterable by for..in grammar, if not, you may need to use a custom formatter(see custom formatter bellow) to serialize/de-serialize it.

Signature:

function version(id: number): PropertyDecorator & ClassDecorator;

ignore control

If you hope some fields of your store to skip persisting, just like an article with big size of detailed content. you can use @ignore decorator to mark it, those fields will not be loaded (even if it is persisted in previous version) in the initial, and also the subsequent change will not trigger the action of persisting.

For example: if we want to ignore the date field in Quick Start, we just need to use @ignore to decorate it:

import { date, ignore } from 'mobx-sync';
import { observable } from 'mobx';

class Store {
  @observable
  foo = 'bar';

  @ignore
  @date
  @observable
  date = new Date();
}

@ignore only supports decorating property.

Signature:

/**
 * works in web environment only
 */
function ignore(target: any, key: string): void;
namespace ignore {
  /**
   * works in both web and ssr environment
   */
  function ssr(target: any, key: string): void;

  /**
   * works in ssr environment only
   */
  function ssrOnly(target: any, key: string): void;
}

custom formatter

Sometimes, your store node is not a pure object, just like Set, Map, observable.map<number, Date>, etc, you may need to use custom formatter (@format) to parse/stringify the data/value.

For example, we use Set<Date> as a field:

import { format } from 'mobx-sync';
import { observable } from 'mobx';

class Store {
  @format(
    (data: string[]) => new Set(data.map((d) => new Date(d))),
    (value: Set<Date>) => Array.from(value, (v) => v.toISOString()),
  )
  @observable
  allowDates = new Set<Date>();
}

Built-in formatters:

  • @date: parse/stringify date
  • @regexp: parse/stringify regexp

Signature:

/**
 * define a custom stringify/parse function for a field, it is useful for
 * builtin objects, just like Date, TypedArray, etc.
 *
 * @example
 *
 * // this example shows how to format a date to timestamp,
 * // and load it from serialized string,
 * // if the date is invalid, it will not be persisted.
 * class SomeStore {
 *   @format<Date, number>(
 *      (timestamp) => new Date(timestamp),
 *      (date) => date ? +date : void 0,
 *   )
 *   dateField = new Date()
 * }
 *
 * @param deserializer - the function to parse the serialized data to
 *      custom object, the first argument is the data serialized by
 *      `serializer`, and the second is the current value of the field.
 * @param serializer - the function to serialize the object to pure js
 *      object or any else could be stringify safely by `JSON.stringify`.
 */
function format<I, O = I>(
  deserializer: (persistedValue: O, currentValue: I) => I,
  serializer?: (value: I) => O,
): PropertyDecorator;

function date(target: any, key: string): void;

function regexp(target: any, key: string): void;

SSR

Sometimes, we hope to use MobX in SSR(Server-Side Rendering), there is no standard way to stringify/load mobx store to/from html template, mobx-sync maybe one.

At first, you need to call config({ ssr: true }) before call any decorator of mobx-sync. And then, you can use JSON.stringify to stringify your state to html template, and then use trunk.init or parseStore to load it to your store.

For example:

// store.ts
import { ignore } from 'mobx-sync'
import { observable } from 'mobx'

export Store {
  @observable userId = 0

  @ignore.ssr
  users = observable.map()
}
// server.ts
import { config } from 'mobx-sync';

config({ ssr: true });

import { Store } from './store';

app.get('/', (_, res) => {
  const store = new Store();

  res.end(`<!DOCTYPE html>
  <html>
  <body>
  <div id=root>${renderToString(<App store={store} />)}</div>
  <script>var __INITIAL_STATE__ = ${JSON.stringify(store).replace(
    /</g,
    '\\u003c',
  )}</script>
  </body>
  </html>`);
});
// client.ts
import { AsyncTrunk } from 'mobx-sync';
import { Store } from './store';

const store = new Store();
const trunk = new AsyncTrunk(store);

trunk.init(__INITIAL_STATE__).then(() => {
  ReactDOM.render(<App store={store} />, document.querySelector('#root'));
});

NOTE: if you do not want to use a trunk to persist/load state from localStorage, just want to use mobx-sync to load SSR state, you can use parseStore(store, state, true) to load it.

For example:

// client.ts
import { parseStore } from 'mobx-sync';
import { Store } from './store';

const store = new Store();

parseStore(store, __INITIAL_STATE__, true);

ReactDOM.render(<App />, document.querySelector('#root'));

Signature:

interface Options {
  ssr: boolean;
}

function config(options: Partial<Options>): void;

function parseStore(store: any, data: any, isFromServer: boolean): void;

async trunk

sync trunk

Both of AsyncTrunk and SyncTrunk is the class to auto load/persist store to storage, the difference between them is the AsyncTrunk runs asynchronously and SyncTrunk runs synchronously.

Signature:

// this is a subset of `Storage`
interface SyncStorage {
  getItem(key: string): string | null;
  setItem(key: string, value: string): void;
  removeItem(key: string): void;
}

// this is a subset of `ReactNative.AsyncStorage`
interface AsyncStorage {
  getItem(key: string): Promise<string | null>;
  setItem(key: string, value: string): Promise<void>;
  removeItem(key: string): Promise<void>;
}

/**
 * sync trunk initial options
 */
export interface SyncTrunkOptions {
  /**
   * storage, SyncStorage only
   * default is localStorage
   */
  storage?: SyncStorage;
  /**
   * the storage key, default is KeyDefaultKey
   */
  storageKey?: string;
  /**
   * the delay time, default is 0
   */
  delay?: number;

  /**
   * error callback
   * @param error
   */
  onError?: (error: any) => void;
}

/**
 * the async trunk initial options
 */
export interface AsyncTrunkOptions {
  /**
   * storage, both AsyncStorage and SyncStorage is supported,
   * default is localStorage
   */
  storage?: AsyncStorage | SyncStorage;
  /**
   * the custom persisted key in storage,
   * default is KeyDefaultKey
   */
  storageKey?: string;
  /**
   * delay milliseconds for run the reaction for mobx,
   * default is 0
   */
  delay?: number;

  /**
   * error callback
   * @param error
   */
  onError?: (error: any) => void;
}

class AsyncTrunk {
  disposer: () => void;
  constructor(store: any, options?: AsyncTrunkOptions);
  init(initialState?: any): Promise<void>;
  // call persist manually
  persist(): Promise<void>;
  // clear persisted state in storage
  clear(): Promise<void>;
  // change the store instance
  updateStore(): Promise<void>;
}

class SyncTrunk {
  disposer: () => void;
  constructor(store: any, options?: SyncTrunkOptions);
  init(initialState?: any): void;
  // call persist manually
  persist(): void;
  // clear persisted state in storage
  clear(): void;
  // change the store instance
  updateStore(): void;
}

License

The MIT License (MIT)

Copyright (c) 2016 acrazing

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

FOSSA Status

mobx-sync's People

Contributors

acrazing avatar dependabot[bot] avatar emilyemorehouse avatar fossabot avatar guoxiaoyang avatar todorone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mobx-sync's Issues

Computed property not working after hydration

I have something like this:

import { observable, computed } from "mobx";

export class EnvironmentModel {
  @observable public id: string;
  @observable public name: string;

  constructor(id: string, name: string) {
    this.id = id;
    this.name = name;
  }

   @computed get initials() {
     let tokens = this.name.split(" ");
     let res = "blah";
     if (tokens.length === 1) {
       res = tokens[0].slice(0, 2);
     } else {
       res = tokens[0][0] + tokens[1][0];
     }

     return res;
   }

}
import { EnvironmentModel } from "../model";
import { RootStore } from "./Root.store";
import { observable, action } from "mobx";
import { ignore } from "mobx-sync";

let localEnv = new EnvironmentModel("local", "Local Environment");

export class EnvironmentStore {
  @ignore root: RootStore;

  @observable.shallow public current: EnvironmentModel = localEnv;
  @observable.shallow
  public environments: EnvironmentModel[] = observable.array([localEnv]);

  constructor(root: RootStore) {
    this.root = root;
  }

  // TODO: Placeholder function
  @action
  public loginToEnvironment(envName: string, email: string, password: string) {
    let newEnv = new EnvironmentModel(envName, envName);
    this.environments.push(newEnv);
    this.switchEnvironment(newEnv.id);
  }

  @action switchEnvironment(envId: string) {
    let env = this.environments.find(e => e.id === envId);
    if (!env) {
      // do something a toast or w/e
      return;
    }

    this.current = env;
  }
}

Everything works fine the first time when the objects are created on runtime, but once my store is rehydrated upon application load, the computed initials is no longer working and returns undefined.

Any idea why this might be happening? Am I doing something wrong?

Handling actions on classes.

I'm using mobx-sync in a React application to persist state for an offline mode. One issue I am facing is that when persisting a store that has an array of objects where those objects have actions for modifying their state, when initialized from storage the JS objects in the store know nothing about the methods that were on the object when it was first added. I can see what, and why the problem is occurring, but at a loss to what would be the best way to address it.

So if I have a ProfileStore that contains a set of Options and ProfileStore has actions to add an option, that is fine. But if Option has an action to update state, after loading that store and it's Options, the loaded Option throws "... is not a function" exceptions. Obviously the array of Option state is not "typed" to the Option class that is defined. I'm left wondering if there is a way to deserialize them in a way that is recognized as that type, or a best practice to alter the structure so that the actions don't rely on the state. I would like options to live under a profile store rather than trying to juggle separate stores for loosely coupled objects.

MobX should be declared in peerDependencies section

I found that mobx-sync requires mobx in dependencies section. In my case I use mobx 4.8 but mobx-sync installed 5.8 (because of "mobx": "*"). So I cannot use it with IE11.

I think that mobx should be declared in peerDependencies section something like this:

"peerDependencies": {
  "mobx": "^4.3.1 || ^5.0.0"
},

Using formatters with TS interface

I have a simple interface

interface Todo {
  title: string;
  deadline: Date;
}

And it persists correctly.
But is there a way for rehydrating Date object without rewriting this to class? I know, that this would be simple class, it's just I don't want to use one when it's not needed.

re-hyrdate/de-serialise JS Date or custom type

Hi, thanks for the lib!

Any guidance on how to rehydrate an object property of type JS Date or a custom type e.g. a Moment date. They persist fine to a string value as they implement the native JS serialisation interface i.e. toJSON(). But just need a way to run when re-hyrdating the save state to call a custom function with code like new Moment(value).

I saw this todo comment in the source code about this requirement.

The @serlizer lib has an @date decorator and a custom decorator.

Persist Multiple Stores?

I am attempting to utilize your package to persist multiple mobx stores as per the example here and have my stores setup in a similar fashion to this:

/*   RootStore.js  */
import {UserStore, TodoStore } from './index.js'
import { AsyncTrunk } from 'mobx-sync';
import AsyncStorage from '@react-native-community/async-storage';

class RootStore {
    constructor() {
        this.userStore = new UserStore()
        this.todoStore = new TodoStore()
    }
}

const rootStore = new RootStore();

const trunk = new AsyncTrunk(rootStore, {
  storageKey: 'myAppStore',
  storage: AsyncStorage,
  onError: error => console.error('TRUNK ERROR', error)
});

export { rootStore, RootStore, trunk };

/*  UserStore.js  */
import {rootStore} from './RootStore.js'

class UserStore {
    constructor(rootStore) {
        this.rootStore = rootStore
    }

    getTodos(user) {
        // access todoStore through the root store
        return this.rootStore.todoStore.todos.filter((todo) => todo.author === user)
    }
}

/*  TodoStore.js */
import {rootStore} from './RootStore.js'

class TodoStore {
    @observable todos = []

    constructor(rootStore) {
        this.rootStore = rootStore
    }
}

I then call the following function to hydrate the stores on app start:

const initApp = () => {
  trunk.init().then(() => {
    console.log('hydrate done', rootStore.userStore); //always undefined
  }
}

rootStore.userStore is always undefined, how can I persist multiple stores using this package?

Thanks.

mobx: 5.15.4
react-native: 0.61.5
mobx-sync: 3.0.0
@react-native-community/async-storage: 1.11.0

Can't get @ignore to work

Hi, thanks for the lib, really liking it so far :)

However, I'm not able to make the @ignore decorator work. All of the fields are persisted correctly (and the observer is reacting correctly on updates).

This is a snippet of my store class:

class Store {
  @ignore
  @observable
  movieData: TMovies | null = null;

  ... other observable fields
}

I've tried the @ignore.ssr and @ignore.ssrOnly variations but the movieData is always persisted.

As extra context, I'm using this with mobx-react like:

function createStore() {
  return new Store();
}


export const StoreProvider: FC = ({children}) => {
  const store = useLocalStore(createStore);
  const [storeReady, setStoreReady] = useState(false);

  const trunk = new AsyncTrunk(store, {
    storage: AsyncStorage,
    storageKey: 'key2',
  });

  useEffect(() => {
    trunk.init().then(() => {
      setStoreReady(true);
    });
  }, []);

  return (
    <Context.Provider value={store}>
      {storeReady ? (
        children
      ) : (
          <Loader />
      )}
    </Context.Provider>
  );
};

Am I doing something wrong?

Any way to handle persistence exceptions?

Local storage is not unlimited, so persistence can sometimes result in failure. Is there any way to detect and respond to this happening when using mobx-sync?

An example of an error that can show up on the console log,
cycle reference occurred > Array [] sync.js:30

Incredibly slow refresh times

Often on a dev server, I will want to refresh the page. However, using this library, refreshes can take 10-15 seconds. Is this normal, or is it specific to my setup?

Not working for arrays

Storing objects is working fine but when it's an array it's not persisted.

@observable list = [{a: '1', b: '2'}];

Example of how to use without decorators?

I am new to this library, but my project is based without decorators because create-react-app does not support them. And the workarounds for supporting decorators could be detrimental to performance/stability.

How do I use this without decorators?

no releases?

this code has no releases on github and no changelog..

How the fallback works? And errors question

Just found this! I was writing my own mobx persistent lib, but this one will save me some time.

If the data isn't locally found, it will keep the initial value?

Also, if there is an error during the save/load, will there be any Error throw?

ReactJs TypeScript - AsyncTrunk is not a constructor

I had issues on mobx-persist and I saw that this package would fit my needs. However, following the tutorial.. I am already getting an error I am stuck at:

Uncaught TypeError: mobx_sync__WEBPACK_IMPORTED_MODULE_9__.AsyncTrunk is not a constructor
at Module.eval (main.tsx?5177:15)
at eval (main.tsx:67)
at Module../main.tsx (app.856980a5f3b10010e12e.js:625)
at webpack_require (856980a5f3b10010e12e.js:785)
at fn (856980a5f3b10010e12e.js:151)
at Object.0 (app.856980a5f3b10010e12e.js:638)
at webpack_require (856980a5f3b10010e12e.js:785)
at checkDeferredModules (856980a5f3b10010e12e.js:46)
at Array.webpackJsonpCallback [as push] (856980a5f3b10010e12e.js:33)
at app.856980a5f3b10010e12e.js:1

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import {Provider} from 'mobx-react';
import {RootStores} from 'app/stores';
import {App} from 'app';
import {createBrowserHistory} from "history";
import {AsyncTrunk} from "mobx-sync";

// prepare MobX stores
const history = createBrowserHistory();
const stores = new RootStores(history).getStoresInstances();
const trunk = new AsyncTrunk(stores, {
    /**
     * @desc custom storage: built in storage is supported
     *  - localStorage
     *  - sessionStorage
     *  - ReactNative.AsyncStorage
     */
    storage: localStorage as any,
    /**
     * @desc custom storage key, the default is `__mobx_sync__`
     */
    storageKey: '__persist_mobx_stores__',
});

trunk.init().then(() => {
    // render react DOM
    console.log("// render react DOM");
    ReactDOM.render(
        <Provider {...stores}>
            <App history={history}/>
        </Provider>,
        document.getElementById('root')
    );
});

Project maintenance

I just wanted to reach out and check if this project is still being (or will be) maintained.

I quite like it, but have noticed a few issues lately with compatibility of dependencies. The biggest being that it seems this library is incompatible with mobx 6. Also it seems the library only supports the deprecated version of the AsyncStorage library in React Native (https://reactnative.dev/docs/asyncstorage).

Thanks for all your work here!

Failed to compile. Can't import the named export '__awaiter' from non EcmaScript module

I'm using new create-react-app app with typescript. Everything was installed correctly.

Error:

Failed to compile.

/Users/alder/node_modules/mobx-sync/lib/async.mjs
Can't import the named export '__awaiter' from non EcmaScript module (only default export is available)

Code:

import { AsyncTrunk } from 'mobx-sync/lib/async'
import { rootStore } from './stores';

const trunk = new AsyncTrunk(rootStore, { storage: localStorage })
trunk.init().then(() => {
    ReactDOM.render(<App />, document.getElementById('root'));    
})

packages.json:

  "dependencies": {
    "@material-ui/core": "^4.0.0-alpha.8",
    "axios": "^0.19.0-beta.1",
    "crypto-ts": "^1.0.2",
    "formik": "^1.5.4",
    "history": "^4.9.0",
    "lodash": "^4.17.11",
    "mobx": "^5.9.4",
    "mobx-react": "beta",
    "mobx-state-router": "^4.0.5",
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-input-mask": "^2.0.4",
    "react-scripts": "^3.0.0",
    "styled-components": "^4.2.0",
    "yup": "^0.27.0"
  },
  "devDependencies": {
    "@types/history": "^4.7.2",
    "@types/lodash": "^4.14.123",
    "@types/material-ui": "^0.21.6",
    "@types/react": "^16.8.14",
    "@types/react-dom": "^16.8.4",
    "@types/react-input-mask": "^2.0.1",
    "@types/styled-components": "^4.1.14",
    "@types/yup": "^0.26.12",
    "@typescript-eslint/eslint-plugin": "^1.7.0",
    "eslint-config-prettier": "^4.2.0",
    "eslint-config-typescript": "^2.0.0",
    "eslint-plugin-react": "^7.12.4",
    "husky": "^2.1.0",
    "lint-staged": "^8.1.5",
    "prettier": "^1.17.0",
    "typescript": "^3.4.5"
  },

No types?

Hey im getting a bunch of errors when trying to use this in my Typescript project.

Im using the version from npm yarn add mobx-sync but it tells me that its missing the type definitions for the module?

I also get runtime errors saying that there are multiple versions of mobx running at once? Perhaps the mobx dependency needs to be peer?

mjs modules aren't compatible with react-create-app

This looks to be related to issue #14, but running a React application with mobx-sync results in import errors. Even the most basic example results in the error:
Can't import the named export '__assign' from non EcmaScript module (only default export is available)

I can see from issue #14 that the suggested fix is a webpack change, however with react-create-app this would require ejecting the configuration to try and tweak the webpack settings, which I would like to avoid since it isn't reversible. Is there a way that I can rebuild the mobx-sync package to be ECMAScript compatible, or otherwise reference it in a way that the module shaker will understand?

@format @date decorators broken for nested items in observable array

Both work on the parent store:

export class TodoListStore {
  @date date2:any
  @format((value) => new moment(value)) date:any

  @observable todos: TodoItem[] = []
}

But do not work on the sub-classes.

export class TodoItem {
   @ignore id: string;

  @date date2:any
  @format((value) => new moment(value)) date:any
}

@ignore works on the subclass - the serialise logic is good, but the de-serialise logic is broken.

When I debug parse-store.ts, the todos observable hits this line only and does not recursively then call parseStore() on the nested object

else if (mobx_1.isObservableArray(storeValue)) {
                // mobx array
                store[key] = mobx_1.observable.array(dataValue);
            }

Maybe this gives a clue?

Can't import @format @date @regexp

I couldn't import the new decorators in v0.6.0 in my app using:
import { format, date, regexp } from 'mobx-sync

I believe you have missed exporting them in index.ts.

I added this line to the file, which fixed the issue:
export { format,date,regexp } from './format';

Inverted behaviour

Is it possible to achieve the inverted behaviour when only specifically decorated properties will be synced with the storage, but all others will not sync by default?

tons of import errors

in my code, i import like this:

import {AsyncTrunk} from "mobx-sync";

results in:

ERROR in ./node_modules/mobx-sync/lib/index.mjs 10:0-37
Can't reexport the named export 'AsyncTrunk' from non EcmaScript module (only default export is available)
 @ ./src/main.tsx
 @ multi (webpack)-dev-server/client?http://localhost:8082 ./src/main.tsx

ERROR in ./node_modules/mobx-sync/lib/index.mjs 13:0-35
Can't reexport the named export 'SyncTrunk' from non EcmaScript module (only default export is available)
 @ ./src/main.tsx
 @ multi (webpack)-dev-server/client?http://localhost:8082 ./src/main.tsx

ERROR in ./node_modules/mobx-sync/lib/index.mjs 14:0-34
Can't reexport the named export 'config' from non EcmaScript module (only default export is available)
 @ ./src/main.tsx
 @ multi (webpack)-dev-server/client?http://localhost:8082 ./src/main.tsx

ERROR in ./node_modules/mobx-sync/lib/index.mjs 11:0-70
Can't reexport the named export 'date' from non EcmaScript module (only default export is available)
 @ ./src/main.tsx
 @ multi (webpack)-dev-server/client?http://localhost:8082 ./src/main.tsx

ERROR in ./node_modules/mobx-sync/lib/index.mjs 11:0-70
Can't reexport the named export 'format' from non EcmaScript module (only default export is available)
 @ ./src/main.tsx
 @ multi (webpack)-dev-server/client?http://localhost:8082 ./src/main.tsx

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.