{"_id":"f-dexie-observable","_rev":"1-d016ca4111fc2a4e7fa8a2f7ac19255e","name":"f-dexie-observable","dist-tags":{"latest":"1.0.0-beta.5"},"versions":{"1.0.0-beta.5":{"name":"f-dexie-observable","version":"1.0.0-beta.5","description":"Addon to Dexie that makes it possible to observe database changes no matter if they occur on other db instance or other window.","main":"dist/dexie-observable.js","module":"dist/dexie-observable.es.js","jsnext:main":"dist/dexie-observable.es.js","typings":"dist/dexie-observable.d.ts","jspm":{"format":"cjs","ignore":["src/"]},"repository":{"type":"git","url":"git+https://github.com/dfahlander/Dexie.js.git"},"keywords":["indexeddb","browser","dexie","addon"],"author":{"name":"David Fahlander"},"contributors":[{"name":"Nikolas Poniros","email":"https://github.com/nponiros"},{"name":"Yury Solovyov","email":"https://github.com/YurySolovyov"},{"name":"Martin Diphoorn","email":"https://github.com/martindiphoorn"},{"name":"Corbin Crutchley","email":"https://github.com/crutchcorn"}],"license":"Apache-2.0","bugs":{"url":"https://github.com/dfahlander/Dexie.js/issues"},"scripts":{"build":"just-build","watch":"just-build --watch","test":"npm run build && npm run test:typings && npm run test:unit && npm run test:integration","test:unit":"karma start test/unit/karma.conf.js --single-run","test:integration":"karma start test/integration/karma.conf.js --single-run","test:typings":"tsc -p test/typings/","test:unit:debug":"karma start test/unit/karma.conf.js --log-level debug","test:integration:debug":"karma start test/integrations/karma.conf.js --log-level debug"},"just-build":{"default":["just-build release test"],"dev":["just-build dexie-observable test"],"dexie-observable":["# Build UMD module","tsc --allowJs -t es5 -m es2015 --outDir tools/tmp/es5/src/ --sourceMap src/Dexie.Observable.js [--watch 'Compilation complete.']","rollup -c tools/build-configs/rollup.config.js","node tools/replaceVersionAndDate.js dist/dexie-observable.js","# eslint ","eslint src --cache"],"release":["just-build dexie-observable","# Copy Dexie.Observable.d.ts to dist and replace version in it","node -e \"fs.writeFileSync('dist/dexie-observable.d.ts', fs.readFileSync('src/Dexie.Observable.d.ts'))\"","node tools/replaceVersionAndDate.js dist/dexie-observable.d.ts","# Minify the default ES5 UMD module","uglifyjs dist/dexie-observable.js -m -c -o dist/dexie-observable.min.js --source-map \"filename=dist/dexie-observable.min.js.map\" --in-source-map dist/dexie-observable.js.map"],"test":["# Build the unit tests (integration tests need no build)","tsc --allowJs --moduleResolution node --lib es2015,dom -t es5 -m es2015 --outDir tools/tmp/es5/test --rootDir ../.. --sourceMap test/unit/unit-tests-all.js [--watch 'Compilation complete.']","rollup -c tools/build-configs/rollup.tests.config.js","eslint test/unit --cache --ignore-pattern bundle.js"]},"homepage":"http://dexie.org","peerDependencies":{"dexie":"^2.0.4"},"devDependencies":{"dexie":"^2.0.4","eslint":"^5.16.0","just-build":"^0.9.16","karma":"^4.1.0","karma-browserstack-launcher":"^1.5.1","karma-chrome-launcher":"^2.0.0","karma-firefox-launcher":"^1.1.0","karma-mocha-reporter":"^2.2.5","karma-qunit":"^3.1.2","qunit":"^2.9.2","rollup":"^0.55.5","rollup-plugin-sourcemaps":"^0.4.1","typescript":"^2.8.3","uglifyjs":"^2.4.10"},"dependencies":{},"_id":"f-dexie-observable@1.0.0-beta.5","_npmVersion":"6.4.1","_nodeVersion":"10.14.0","_npmUser":{"name":"bigmurry","email":"hhdiao@siom.ac.cn"},"dist":{"integrity":"sha512-sOn+q8KoBKDjKxmhxkuLCln0M7349G809tLmF7vyLgoRB66ypJ9oEBmRrSXnegFiEA1WzamA6uGYvwPqL7Q7eQ==","shasum":"e80a9b169aa7d65764be2e090e22d78a3959c808","tarball":"https://registry.npmjs.org/f-dexie-observable/-/f-dexie-observable-1.0.0-beta.5.tgz","fileCount":11,"unpackedSize":353521,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcztuiCRA9TVsSAnZWagAAz8MP/13wLVJCqSiDlNWplG0/\nFfqkUMK9G9Nn0vXDIeWyH8VIfGPJ5U5iWDSNuFEjz/zZtEpQsMaeJbZrhMDe\nlRlKX/BXY9zxHrdMw+14yTB3Bd4g4ivbxRBkRC2mEcsrPwCvTCcefihfNhQm\nkgFQNkTbYMNIvu7KhojF6MLWGKF8oKmjHyhe0f9mydTWTrxr5opumWWHgu8Z\nUQ9ushaox8FABKZSNg7AaZ8Fx6R8dyvawj4zu9uaTrSrs9xZGAA+DrrP5eVL\nz4mVETcq/++cUtfm7jx8A3eB6aNYfx+RjS9t8Yuq6nj7YMK6v+XTgFvCHXcA\nD+Se0oFrKIOnnM00P8BaYUAF5vx+54+6JfBkqpIxSIme6SUaU20cpzYdl1PR\ny33u309KYu090qNJEvHWYnpDfbRhTriv1XvZQErtEEBjP4GtGIU9SqVuSGOZ\n5c98FfA2Bmt3BM0KgFk6k/QNbGUgacH++d8uws2FjHm1fqRWgnlSwPZNrsKo\nrixpgFJ8juJDBNO3ZqNqDcEOsZNgImTzOIartQLMAF/yEe7giDbI1XW/EIy1\nGfx5eHoRmYiJE1BFuOtdPkjTgirMBX6m2cE4eEDCrt8Cndb0M9u/GNpaGzRh\ndiK+kN5gF504hJAGXvdarFDqz72M2VjXNEcv6MKFh05SQ05Ex6zqq+G19VDr\nLg0h\r\n=kTjV\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEezBpQqWT8PHiB6kApsBZSeD2eBEJKBmvQ6xVUwvmb7AiAzv5lPwyUnkoj7i7VC2bz1fkcXC/+sBxvIUcjfVUIwfQ=="}]},"maintainers":[{"name":"bigmurry","email":"hhdiao@siom.ac.cn"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/f-dexie-observable_1.0.0-beta.5_1557060513513_0.4779654834758644"},"_hasShrinkwrap":false}},"time":{"created":"2019-05-05T12:48:33.512Z","1.0.0-beta.5":"2019-05-05T12:48:34.305Z","modified":"2022-05-02T01:56:58.978Z"},"maintainers":[{"name":"bigmurry","email":"hhdiao@siom.ac.cn"}],"description":"Addon to Dexie that makes it possible to observe database changes no matter if they occur on other db instance or other window.","homepage":"http://dexie.org","keywords":["indexeddb","browser","dexie","addon"],"repository":{"type":"git","url":"git+https://github.com/dfahlander/Dexie.js.git"},"contributors":[{"name":"Nikolas Poniros","email":"https://github.com/nponiros"},{"name":"Yury Solovyov","email":"https://github.com/YurySolovyov"},{"name":"Martin Diphoorn","email":"https://github.com/martindiphoorn"},{"name":"Corbin Crutchley","email":"https://github.com/crutchcorn"}],"author":{"name":"David Fahlander"},"bugs":{"url":"https://github.com/dfahlander/Dexie.js/issues"},"license":"Apache-2.0","readme":"# Dexie.Observable.js\n\nObserve changes to database - even when they happen in another browser window.\n\n### Install\n```\nnpm install dexie --save\nnpm install dexie-observable --save\n```\n\n### Use\n```js\nimport Dexie from 'dexie';\nimport 'dexie-observable';\n\n// Use Dexie as normally - but you can also subscribe to db.on('changes').\n\n```\n\n#### Usage with existing DB\n\nIn case you want to use Dexie.Observable with your existing database, you will have to do a schema upgrade. Without it Dexie.Observable will not be able to properly work.\n\n```javascript\nimport Dexie from 'dexie';\nimport 'dexie-observable';\n\nvar db = new Dexie('myExistingDb');\ndb.version(1).stores(... existing schema ...);\n\n// Now, add another version, just to trigger an upgrade for Dexie.Observable\ndb.version(2).stores({}); // No need to add / remove tables. This is just to allow the addon to install its tables.\n```\n\n### Dependency Tree\n\n * [Dexie.Syncable.js](http://dexie.org/docs/Syncable/Dexie.Syncable.js)\n   * **Dexie.Observable.js**\n     * [Dexie.js](http://dexie.org/docs/Dexie/Dexie.js)\n       * [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API)\n\n### Source\n\n[Dexie.Observable.js](https://github.com/dfahlander/Dexie.js/blob/master/addons/Dexie.Observable/src/Dexie.Observable.js)\n\n### Description\n\nDexie.Observable is an add-on to Dexie.js makes it possible to listen for changes on the database even if the changes are made in a foreign window. The addon provides a \"storage\" event for IndexedDB, much like the storage event (onstorage) for localStorage.\n\nIn contrary to the [Dexie CRUD hooks](http://dexie.org/docs/Tutorial/Design#the-crud-hooks-create-read-update-delete), this event reacts not only on changes made on the current db instance but also on changes occurring on db instances in other browser windows. <u>This enables a Web Apps to react to database changes and update their views accordingly.</u>\n\nDexie.Observable is also the base of [Dexie.Syncable.js](http://dexie.org/docs/Syncable//Dexie.Syncable.js) - an add-on that enables two-way replication with a remote server.\n\n### Extended Methods, Properties and Events\n\n#### UUID key generator\nWhen defining your stores in [Version.stores()](http://dexie.org/docs/Version/Version.stores()) you may use the $$ (double dollar) prefix to your primary key. This will make it auto-generated to a UUID string. See sample below.\n\n#### Dexie.Observable.createUUID()\nA static method added to Dexie that creates a UUID. This method is used internally when using the $$ prefix to primary keys. To change the format of $$ primary keys, just override Dexie.createUUID by setting it to your desired function instead.\n\n#### db.on('changes') event\nSubscribe to any database changes no matter if they occur locally or in other browser window.\n\nParameters to your callback:\n\n<table>\n<tr><td>changes : Array&lt;<a href=\"http://dexie.org/docs/Observable/Dexie.Observable.DatabaseChange\">DatabaseChange</a>&gt;</td><td>Array of changes that have occured in database (locally or in other window) since last time event was triggered, or the time of starting subscribing to changes.</td></tr>\n<tr><td>partial: Boolean</td><td>True in case the array does not contain all changes. In this case, your callback will soon be called again with the additional changes and partial=false when all changes are delivered.</td></tr>\n</table>\n\n#### Example (here we're using plain ES6 script tags):\n```html\n<html>\n    <head>\n    <script src=\"dexie.min.js\"></script>\n    <script src=\"dexie-observable.min.js\"></script> <!-- Enable DB observation -->\n    <script>\n        var db = new Dexie(\"ObservableTest\");\n        db.version(1).stores({\n            friends: \"$$uuid,name\"\n        });\n        db.on('changes', function (changes) {\n            changes.forEach(function (change) {\n                switch (change.type) {\n                    case 1: // CREATED\n                        console.log('An object was created: ' + JSON.stringify(change.obj);\n                        break;\n                    case 2: // UPDATED\n                        console.log('An object with key ' + change.key + ' was updated with modifications: ' + JSON.stringify(change.mods));\n                        break;\n                    case 3: // DELETED\n                        console.log('An object was deleted: ' + JSON.stringify(change.oldObj);\n                        break;\n            });\n        });\n        db.open();\n        // Make an initial put() - will result in a CREATE-change:\n        db.friends.put({name: \"Kalle\"}).then(function(primKey) {\n            // Call put() with existing primary key - will result in an UPDATE-change:\n            db.friends.put({uuid: primKey, name: \"Olle\"}).then (function () {\n                // Call delete() will result in a DELETE-change:\n                db.friends.delete(primKey);\n            });\n        });\n\n        // Result that will be logged:\n        // An object was created: {\"uuid\": \"23bada36-d27a-4e78-a978-1ab3c4129cd0\", name: \"Kalle\"}\n        // An object with key: 23bada36-d27a-4e78-a978-1ab3c4129cd0 was updated with modifications: {\"name\": \"Olle\"}\n        // An object was deleted: {\"uuid\": \"23bada36-d27a-4e78-a978-1ab3c4129cd0\", name: \"Olle\"}\n    </script>\n    </head>\n    <body>\n    </body>\n</html>\n```\n","readmeFilename":"README.md"}