1.0.16 • Published 6 months ago

mobx-state-tree-persist-and-sync v1.0.16

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

mobx-state-tree-persist-and-sync

TODO - at the moment, naively the whole stores data is sent every time there is an update, this needs to be replaced with a solution that can only send and receive the changes within the stores.

import {observer} from "mobx-react-lite";
import {types} from "mobx-state-tree";
import {persistAndSync} from "mobx-state-tree-persist-and-sync";
import AsyncStorage from "@react-native-async-storage/async-storage";

const FooModel = types.model("foo").props({
	test: "hello world"
});

const BarModel = types.model("bar").props({
	test: false
});

const RootModel = types
	.model("root")
	.props({
		isHydrated: false,
		foo: FooModel,
		bar: BarModel
	})
	.actions(self => ({
		setHydrated() {
			self.isHydrated = true;
		}
	}));

const rootStore = RootModel.create({
	foo: {},
	bar: {}
});

persistAndSync(
	rootStore,
	["foo"],
	["bar"],
	AsyncStorage,
	syncUpdate //todo explain server side
).then(() => rootStore.setHydrated());

const App = observer(() => {
	if (!rootStore.isHydrated) {
		return null;
	}

	return <Text>{rootStore.foo.test}</Text>;
});
1.0.2

7 months ago

1.0.1

7 months ago

1.0.16

6 months ago

1.0.9

6 months ago

1.0.8

6 months ago

1.0.7

6 months ago

1.0.6

7 months ago

1.0.5

7 months ago

1.0.4

7 months ago

1.0.3

7 months ago

1.0.11

6 months ago

1.0.10

6 months ago

1.0.15

6 months ago

1.0.14

6 months ago

1.0.13

6 months ago

1.0.12

6 months ago

1.0.0

9 months ago