{"_id":"mobx-state-tree-firebase","_rev":"28-3b9bcb325397f7605c44ac0c65f46ff9","name":"mobx-state-tree-firebase","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"mobx-state-tree-firebase","version":"1.0.0","keywords":["Firebase","mobx-state-tree","mobx"],"author":{"name":"sanketsahu@gmail.com"},"license":"Apache-2.0","_id":"mobx-state-tree-firebase@1.0.0","maintainers":[{"name":"amithms92","email":"amith@geekyants.com"}],"homepage":"https://github.com/GeekyAnts/mobx-state-tree-firebase#readme","bugs":{"url":"https://github.com/GeekyAnts/mobx-state-tree-firebase/issues"},"dist":{"shasum":"9b05098ec141523d16929699a59b81e28a6d90be","tarball":"https://registry.npmjs.org/mobx-state-tree-firebase/-/mobx-state-tree-firebase-1.0.0.tgz","integrity":"sha512-9RRrG5nr6JMZFPgQFvnEdqAUuHNAX+iTUvfJimpk0sY1mtqmdMkTELnymsw5SoAV2WQ0nYE7L0xCDMa1x7xtAw==","signatures":[{"sig":"MEQCIHYq1P/swYJWP4dfmMNCKmxMP8O1yEoc/yctl1JYvZr+AiB5Ek7J23xdGUAzzh/ar5qZQb/rN6TnOybFQxzfvbmwYw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"./dist/index.js","_from":".","_shasum":"9b05098ec141523d16929699a59b81e28a6d90be","gitHead":"c089250b79aaa99df1790c966c02456a12a03ae6","scripts":{"test":"echo \"Error: no test specified\" && exit 1","build":"tsc","prepublish":"npm run build"},"typings":"./dist/index.d.ts","_npmUser":{"name":"amithms92","email":"amith@geekyants.com"},"repository":{"url":"git+https://github.com/GeekyAnts/mobx-state-tree-firebase.git","type":"git"},"_npmVersion":"3.3.6","description":"Firebase Integration for mobx-state-tree","directories":{},"_nodeVersion":"5.0.0","dependencies":{"typescript":"^2.5.3"},"peerDependencies":{"firebase":"^4.5.0","mobx-state-tree":"^1.0.0"},"_npmOperationalInternal":{"tmp":"tmp/mobx-state-tree-firebase-1.0.0.tgz_1507633954902_0.5096710657235235","host":"s3://npm-registry-packages"}}},"time":{"created":"2017-10-10T11:12:34.991Z","modified":"2026-06-05T07:29:58.025Z","1.0.0":"2017-10-10T11:12:34.991Z","1.0.1":"2017-10-10T12:39:14.629Z"},"bugs":{"url":"https://github.com/GeekyAnts/mobx-state-tree-firebase/issues"},"author":{"name":"sanketsahu@gmail.com"},"license":"Apache-2.0","homepage":"https://github.com/GeekyAnts/mobx-state-tree-firebase#readme","keywords":["Firebase","mobx-state-tree","mobx"],"repository":{"url":"git+https://github.com/GeekyAnts/mobx-state-tree-firebase.git","type":"git"},"description":"Firebase Integration for mobx-state-tree","maintainers":[{"email":"surajahmedc@gmail.com","name":"surajahmedc"},{"email":"npm@sahusoft.com","name":"geekyants-admin"},{"email":"sanketsahu@gmail.com","name":"sanketsahu"},{"email":"sarika@geekyants.com","name":"sarika_geekyants"},{"email":"pratik@geekyants.com","name":"kumarpratik"},{"email":"atul@geekyants.com","name":"atulrpandey"},{"email":"khalid@geekyants.com","name":"khalidimam1201"},{"email":"gauravp@geekyants.com","name":"gauravp"},{"email":"gauravprwl14@gmail.com","name":"gauravprwl14"}],"readme":"# Mobx-state-tree firebase model\n\nThis package will ease the process of setting up all your CRUD operations in your react-native/react project which uses mobx-state-tree as the state management library.\n\n\n### Prerequisites\n\nYou will need - \n\n```\nNode (v6+)\nnpm (v3+)\n```\n\n### Installing\n\nInstalling is pretty straightforward, if you have the prerequisites set up. Just copy the below code to your terminal in your project directory. Note that this has a peer dependency of mobx and firebase (duh!).\n\n```\nnpm install mst-firebase --save\n```\n\n## Getting Started\n\nNow that you have installed the package you are all set to start playing with it!\n\nFirst, import the package to wherever you need to save the mst model.\n```js\nimport { FirebaseModel } from 'FirebaseModel';\n```\nThis will only provide the save/update function, to get all the other functions you can import them seperately like \n\n```js\nimport { findById } from 'FirebaseModel';\nimport { findAllWhere } from 'FirebaseModel';\n```\n\nNext you have to \"inherit\" all the properties of the FirebaseModel to your mobx-state-tree model. An example for this would be - \n\n```js\nconst Post = FirebaseBaseModel.named(\"Post\")\n  .props({\n    _path: \"posts\",\n    title: types.string,\n    description: types.string\n  })\n  .actions((self) => {\n    \n    return {\n      updateTitle(newTitle: string) {\n        self.title = newTitle;\n      },\n    };\n  });\n```\n\nNow that Let's go over some common use cases.\n\n1) To create a new entry -\n\n```js\nconst FirstPost = Post.create({\n  title: 'Hey!',\n  description: 'Please save this.',\n});\n\nFirstPost.save();\n```\nAnd voila! A new post is added! <br> \n\n2) To update a model - \n\n```js\nconst FirstPost = Post.create({\n  title: 'Hey!',\n  description: 'updated?',\n  _id: \"-Kw4VJxqhKSiA3r2K8ue\" \n});\n\nFirstPost.save();\n```\n<br>\nTo update an existing post you will have to pass the id in the Model as a private property. Based on this it will create/update a new entry in the firebase model. \n\n3) To find an entry in your firebase database by it's Id - \n\n```js\nfindById(\n\tYourModel,\n    IdYouWantToGet)\n    .then(success =>\n    \t//do stuff on success here\n\t}, error => {\n    \t//do stuff on error here\n    });\n    \n```\nThe first argument is your mobx-state-tree model and the second argument is the Id of the object you are trying to access. <br /> <br />\nLet us look at an example where we want to fetch a user with a particular user id.\n\n```js\nfindById(Post, \"-Kw0DPoUeMBtsB-ZrZdQ\").then(success => {\n  console.log(\"success\", getSnapshot(success));\n});\n```\n4) To find all entries in your firebase database by a condition - \n\n```js\nfindAllWhere(\n\tYourModel,\n\tPropYouWantToFilterBy,\n    OperatorYouWantToFilterBy,\n    ValueYouWantToFilterBy)\n    .then(success =>\n    \t//do stuff on success here\n\t}, error => {\n    \t//do stuff on error here\n    });\n);\n```\nNote that the first argument is your mobx-state-tree model, second is the column on which you want to add the condition, third is the operator(supported operators right now are =,>,< and between), fourth is the value to filter by. <br />\n<br />\nLet us look at an example where we want to fetch all posts with the title as Lorem ipsum.\n\n```js\nfindAllWhere(Post, 'title', '=', 'Lorem ipsum').then(success => {\n  console.log(\"success\", success);\n});\n```\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details\n","readmeFilename":"Readme.MD"}