@posva/vuefire-core
Advanced tools
Comparing version 1.1.2 to 2.0.0
{ | ||
"name": "@posva/vuefire-core", | ||
"version": "1.1.2", | ||
"version": "2.0.0", | ||
"description": "Shared code for vue + Firebase apps used by vuefire and vuexfire", | ||
@@ -25,7 +25,7 @@ "author": "Eduardo San Martin Morote <posva13@gmail.com>", | ||
"scripts": { | ||
"pretest": "npm run lint", | ||
"test": "npm run unit", | ||
"unit": "jest", | ||
"pretest": "yarn run lint", | ||
"test": "yarn run test:unit", | ||
"test:unit": "jest", | ||
"lint": "eslint --fix src test", | ||
"dev": "npm run unit -- --watchAll" | ||
"dev": "yarn run test:unit -- --watchAll" | ||
}, | ||
@@ -38,3 +38,3 @@ "bugs": { | ||
"@babel/preset-env": "^7.4.4", | ||
"@posva/vuefire-test-helpers": "^1.0.4", | ||
"@posva/vuefire-test-helpers": "^1.1.0", | ||
"@types/jest": "^24.0.12", | ||
@@ -47,3 +47,3 @@ "eslint": "^5.9.0", | ||
}, | ||
"gitHead": "ed1ee4682cc45f26b27e3e0ef8bfc9a4b3e51205" | ||
"gitHead": "694123cacbc447f1e7d62a07d284e019d38f76da" | ||
} |
@@ -9,2 +9,4 @@ import { | ||
const DEFAULT_OPTIONS = { maxRefDepth: 2, reset: true } | ||
export * from './rtdb' | ||
@@ -78,4 +80,5 @@ | ||
{ vm, key, collection, ops, resolve, reject }, | ||
options = { maxRefDepth: 2 } | ||
options = DEFAULT_OPTIONS | ||
) { | ||
options = Object.assign({}, DEFAULT_OPTIONS, options) // fill default values | ||
// TODO support pathes? nested.obj.list (walkSet) | ||
@@ -170,3 +173,3 @@ // NOTE use ops object | ||
// reset resolve to noop | ||
resolve = _ => {} | ||
resolve = () => {} | ||
} | ||
@@ -184,4 +187,9 @@ } | ||
// TODO: we could allow an argument to unbind to override reset | ||
return () => { | ||
unbind() | ||
if (options.reset !== false) { | ||
const value = typeof options.reset === 'function' ? options.reset() : [] | ||
ops.set(vm, key, value) | ||
} | ||
arraySubs.forEach(unsubscribeAll) | ||
@@ -193,3 +201,3 @@ } | ||
{ snapshot, target, path, subs, ops, depth = 0, resolve }, | ||
options = { maxRefDepth: 2 } | ||
options | ||
) { | ||
@@ -235,5 +243,3 @@ const [data, refs] = extractRefs(snapshot, walkGet(target, path)) | ||
} else { | ||
// NOTE use ops | ||
ops.set(target, path, null) | ||
// walkSet(target, path, null) | ||
resolve(path) | ||
@@ -261,4 +267,5 @@ } | ||
{ vm, key, document, resolve, reject, ops }, | ||
options | ||
options = DEFAULT_OPTIONS | ||
) { | ||
options = Object.assign({}, DEFAULT_OPTIONS, options) // fill default values | ||
// TODO warning check if key exists? | ||
@@ -292,2 +299,6 @@ // const boundRefs = Object.create(null) | ||
unbind() | ||
if (options.reset !== false) { | ||
const value = typeof options.reset === 'function' ? options.reset() : null | ||
ops.set(vm, key, value) | ||
} | ||
unsubscribeAll(subs) | ||
@@ -294,0 +305,0 @@ } |
import { createRecordFromRTDBSnapshot, indexForKey } from './utils' | ||
export function rtdbBindAsObject ({ vm, key, document, resolve, reject, ops }) { | ||
const DEFAULT_OPTIONS = { reset: true } | ||
export function rtdbBindAsObject ( | ||
{ vm, key, document, resolve, reject, ops }, | ||
options = DEFAULT_OPTIONS | ||
) { | ||
options = Object.assign({}, DEFAULT_OPTIONS, options) | ||
const listener = document.on( | ||
@@ -15,6 +21,14 @@ 'value', | ||
document.off('value', listener) | ||
if (options.reset !== false) { | ||
const value = typeof options.reset === 'function' ? options.reset() : null | ||
ops.set(vm, key, value) | ||
} | ||
} | ||
} | ||
export function rtdbBindAsArray ({ vm, key, collection, resolve, reject, ops }) { | ||
export function rtdbBindAsArray ( | ||
{ vm, key, collection, resolve, reject, ops }, | ||
options = DEFAULT_OPTIONS | ||
) { | ||
options = Object.assign({}, DEFAULT_OPTIONS, options) | ||
const array = [] | ||
@@ -70,3 +84,7 @@ ops.set(vm, key, array) | ||
collection.off('child_moved', childMoved) | ||
if (options.reset !== false) { | ||
const value = typeof options.reset === 'function' ? options.reset() : [] | ||
ops.set(vm, key, value) | ||
} | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17479
513