Skip to content

Commit

Permalink
Release 1.16 🦔 [merge]
Browse files Browse the repository at this point in the history
  • Loading branch information
mesqueeb authored Oct 14, 2018
2 parents 57160ef + e15ba07 commit d4f4f73
Show file tree
Hide file tree
Showing 60 changed files with 10,009 additions and 483 deletions.
6 changes: 5 additions & 1 deletion build/rollup.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ export default [
],
}),
defaults({
input: 'test/helpers/index.js',
input: 'test/helpers/index.ts',
output: [ {file: 'test/helpers/index.cjs.js', format: 'cjs'} ]
}),
defaults({
input: 'src/utils/setDefaultValues.ts',
output: [ {file: 'test/helpers/utils/setDefaultValues.js', format: 'cjs'} ]
})
]
173 changes: 149 additions & 24 deletions dist/index.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ function pluginState () {
_sync: {
signedIn: false,
userId: null,
unsubscribe: null,
pathVariables: {},
patching: false,
syncStack: {
Expand Down Expand Up @@ -125,9 +126,10 @@ function error (error) {
* a function returning the mutations object
*
* @export
* @param {object} userState
* @returns {AnyObject} the mutations object
*/
function pluginMutations () {
function pluginMutations (userState) {
return {
SET_PATHVARS: function (state, pathVars) {
var self = this;
Expand All @@ -138,6 +140,31 @@ function pluginMutations () {
state._conf.firestorePath = path;
});
},
RESET_VUEX_EASY_FIRESTORE_STATE: function (state) {
var self = this;
var _sync = merge(state._sync, {
unsubscribe: null,
pathVariables: {},
patching: false,
syncStack: {
inserts: [],
updates: {},
deletions: [],
propDeletions: [],
debounceTimer: null,
},
fetched: {},
stopPatchingTimeout: null
});
var newState = merge(userState, { _sync: _sync });
if (state._conf.statePropName) {
Object.keys(newState).forEach(function (key) {
self._vm.$set(state, key, newState[key]);
});
return self._vm.$set(state, state._conf.statePropName, {});
}
state = newState;
},
resetSyncStack: function (state) {
state._sync.syncStack = {
updates: {},
Expand Down Expand Up @@ -226,6 +253,43 @@ var __assign = function() {
return __assign.apply(this, arguments);
};

function __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}

function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}

/**
* convert to new Date() if defaultValue == '%convertTimestamp%'
*
Expand Down Expand Up @@ -512,13 +576,52 @@ function getValueFromPayloadPiece(payloadPiece) {
* @returns {AnyObject} the actions object
*/
function pluginActions (Firebase$$1) {
var _this = this;
return {
duplicate: function (_a, id) {
var state = _a.state, getters = _a.getters, commit = _a.commit, dispatch = _a.dispatch;
return __awaiter(_this, void 0, void 0, function () {
var _b, doc, dId, idMap;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
if (!getters.collectionMode)
return [2 /*return*/, console.error('[vuex-easy-firestore] You can only duplicate in \'collection\' mode.')];
if (!id)
return [2 /*return*/, {}];
doc = merge(getters.storeRef[id], { id: null });
return [4 /*yield*/, dispatch('insert', doc)];
case 1:
dId = _c.sent();
idMap = (_b = {}, _b[id] = dId, _b);
return [2 /*return*/, idMap];
}
});
});
},
duplicateBatch: function (_a, ids) {
var _this = this;
var state = _a.state, getters = _a.getters, commit = _a.commit, dispatch = _a.dispatch;
if (ids === void 0) { ids = []; }
if (!getters.collectionMode)
return;
var doc = merge(getters.storeRef[id], { id: null });
return dispatch('insert', doc);
return console.error('[vuex-easy-firestore] You can only duplicate in \'collection\' mode.');
if (!isWhat.isArray(ids) || !ids.length)
return {};
var idsMap = ids.reduce(function (carry, id) { return __awaiter(_this, void 0, void 0, function () {
var idMap;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, dispatch('duplicate', id)];
case 1:
idMap = _a.sent();
return [4 /*yield*/, carry];
case 2:
carry = _a.sent();
return [2 /*return*/, Object.assign(carry, idMap)];
}
});
}); }, {});
return idsMap;
},
patchDoc: function (_a, _b) {
var state = _a.state, getters = _a.getters, commit = _a.commit, dispatch = _a.dispatch;
Expand Down Expand Up @@ -802,7 +905,7 @@ function pluginActions (Firebase$$1) {
}
// make a promise
return new Promise(function (resolve, reject) {
dbRef.onSnapshot(function (querySnapshot) {
var unsubscribe = dbRef.onSnapshot(function (querySnapshot) {
var source = querySnapshot.metadata.hasPendingWrites ? 'local' : 'server';
if (!getters.collectionMode) {
if (!querySnapshot.data()) {
Expand Down Expand Up @@ -838,8 +941,18 @@ function pluginActions (Firebase$$1) {
state._sync.patching = 'error';
return reject(error$$1);
});
state._sync.unsubscribe = unsubscribe;
});
},
closeDBChannel: function (_a, _b) {
var getters = _a.getters, state = _a.state, commit = _a.commit, dispatch = _a.dispatch;
var _c = (_b === void 0 ? { clearModule: false } : _b).clearModule, clearModule = _c === void 0 ? false : _c;
if (clearModule) {
commit('RESET_VUEX_EASY_FIRESTORE_STATE');
}
if (isWhat.isFunction(state._sync.unsubscribe))
return state._sync.unsubscribe();
},
set: function (_a, doc) {
var commit = _a.commit, dispatch = _a.dispatch, getters = _a.getters, state = _a.state;
if (!doc)
Expand Down Expand Up @@ -872,17 +985,19 @@ function pluginActions (Firebase$$1) {
}
// check for hooks
if (state._conf.sync.insertHook) {
return state._conf.sync.insertHook(storeUpdateFn, newDoc, store);
state._conf.sync.insertHook(storeUpdateFn, newDoc, store);
return newDoc.id;
}
return storeUpdateFn(newDoc);
storeUpdateFn(newDoc);
return newDoc.id;
},
insertBatch: function (_a, docs) {
var state = _a.state, getters = _a.getters, commit = _a.commit, dispatch = _a.dispatch;
var store = this;
if (!getters.signedIn)
return 'auth/invalid-user-token';
if (!isWhat.isArray(docs) || !docs.length)
return;
return [];
var newDocs = docs.reduce(function (carry, _doc) {
var newDoc = getValueFromPayloadPiece(_doc);
if (!newDoc.id)
Expand All @@ -899,9 +1014,11 @@ function pluginActions (Firebase$$1) {
}
// check for hooks
if (state._conf.sync.insertBatchHook) {
return state._conf.sync.insertBatchHook(storeUpdateFn, newDocs, store);
state._conf.sync.insertBatchHook(storeUpdateFn, newDocs, store);
return newDocs.map(function (_doc) { return _doc.id; });
}
return storeUpdateFn(newDocs);
storeUpdateFn(newDocs);
return newDocs.map(function (_doc) { return _doc.id; });
},
patch: function (_a, doc) {
var state = _a.state, getters = _a.getters, commit = _a.commit, dispatch = _a.dispatch;
Expand All @@ -922,16 +1039,20 @@ function pluginActions (Firebase$$1) {
}
// check for hooks
if (state._conf.sync.patchHook) {
return state._conf.sync.patchHook(storeUpdateFn, value, store);
state._conf.sync.patchHook(storeUpdateFn, value, store);
return id;
}
return storeUpdateFn(value);
storeUpdateFn(value);
return id;
},
patchBatch: function (_a, _b) {
var state = _a.state, getters = _a.getters, commit = _a.commit, dispatch = _a.dispatch;
var doc = _b.doc, _c = _b.ids, ids = _c === void 0 ? [] : _c;
var store = this;
if (!doc)
return;
return [];
if (!isWhat.isArray(ids) || !ids.length)
return [];
// define the store update
function storeUpdateFn(_doc, _ids) {
_ids.forEach(function (_id) {
Expand All @@ -941,9 +1062,11 @@ function pluginActions (Firebase$$1) {
}
// check for hooks
if (state._conf.sync.patchBatchHook) {
return state._conf.sync.patchBatchHook(storeUpdateFn, doc, ids, store);
state._conf.sync.patchBatchHook(storeUpdateFn, doc, ids, store);
return ids;
}
return storeUpdateFn(doc, ids);
storeUpdateFn(doc, ids);
return ids;
},
delete: function (_a, id) {
var state = _a.state, getters = _a.getters, commit = _a.commit, dispatch = _a.dispatch;
Expand All @@ -967,16 +1090,16 @@ function pluginActions (Firebase$$1) {
}
// check for hooks
if (state._conf.sync.deleteHook) {
return state._conf.sync.deleteHook(storeUpdateFn, id, store);
state._conf.sync.deleteHook(storeUpdateFn, id, store);
return id;
}
return storeUpdateFn(id);
storeUpdateFn(id);
return id;
},
deleteBatch: function (_a, ids) {
var state = _a.state, getters = _a.getters, commit = _a.commit, dispatch = _a.dispatch;
if (!isWhat.isArray(ids))
return;
if (!ids.length)
return;
if (!isWhat.isArray(ids) || !ids.length)
return [];
var store = this;
// define the store update
function storeUpdateFn(_ids) {
Expand All @@ -998,9 +1121,11 @@ function pluginActions (Firebase$$1) {
}
// check for hooks
if (state._conf.sync.deleteBatchHook) {
return state._conf.sync.deleteBatchHook(storeUpdateFn, ids, store);
state._conf.sync.deleteBatchHook(storeUpdateFn, ids, store);
return ids;
}
return storeUpdateFn(ids);
storeUpdateFn(ids);
return ids;
},
_stopPatching: function (_a) {
var state = _a.state, commit = _a.commit;
Expand Down Expand Up @@ -1246,7 +1371,7 @@ function iniModule (userConfig, FirebaseDependency) {
return {
namespaced: true,
state: merge(pluginState(), userState, docContainer, { _conf: conf }),
mutations: merge(userMutations, pluginMutations()),
mutations: merge(userMutations, pluginMutations(merge(userState, { _conf: conf }))),
actions: merge(userActions, pluginActions(FirebaseDependency)),
getters: merge(userGetters, pluginGetters(FirebaseDependency))
};
Expand Down
Loading

0 comments on commit d4f4f73

Please sign in to comment.