SHARE
TWEET

Untitled

a guest Apr 27th, 2018 268 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import * as React from "react";
  2. import * as ReactDOM from "react-dom";
  3. import { observer, inject } from "mobx-react";
  4. import { types, applySnapshot } from "mobx-state-tree";
  5.  
  6. const Admin = types.model({
  7.     name: types.string,
  8.     password: types.string
  9.   })
  10.  
  11.   const User = types.model({
  12.     login: types.string,
  13.     email: types.string,
  14.     active: false,
  15.     created: types.optional(types.Date, () => new Date()),
  16.     citizen: types.optional(types.string, "")
  17.   })
  18.  
  19.   const RootStore = types.model({
  20.     admins: types.map(Admin),
  21.     users: types.optional(types.map(User), {}),
  22.     test: "Hello Word!"
  23.   })
  24.  
  25.   const store = RootStore.create({
  26.     admins: {"1": {name: "superadmin", password: "pass"}},
  27.     users: {
  28.       "1": {
  29.         login: "testuser",
  30.         email: "test@mail.ru",
  31.         active: true,
  32.         citizen: "RU"
  33.       }
  34.     }
  35.   })
  36.  
  37. const App = inject("store")(observer(({store}) => {
  38.     return (
  39.       <div>
  40.         <div>{store.test}</div>
  41.         <div>{store.users.values().map((user: any) => <div>{user}</div>)}</div>
  42.       </div>
  43.     )
  44.   }))
  45.  
  46. ReactDOM.render(
  47.     <App store={store} />,
  48.     document.getElementById("root")
  49. )
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top