How to use the is-what.isFunction function in is-what

To help you get started, we’ve selected a few is-what examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mesqueeb / vuex-easy-firestore / test / helpers / index.cjs.js View on Github external
switch (change) {
                    case 'added':
                        commit('INSERT_DOC', _doc);
                        break;
                    case 'removed':
                        commit('DELETE_DOC', id);
                        break;
                    default:
                        dispatch('deleteMissingProps', _doc);
                        commit('PATCH_DOC', _doc);
                        break;
                }
            }
            // get user set sync hook function
            var syncHookFn = state._conf.serverChange[change + 'Hook'];
            if (isWhat.isFunction(syncHookFn)) {
                syncHookFn(storeUpdateFn, doc, id, store, 'server', change);
            }
            else {
                storeUpdateFn(doc);
            }
        },
        deleteMissingProps: function (_a, doc) {
github mesqueeb / vuex-easy-firestore / dist / index.cjs.js View on Github external
dispatch('setUserId');
            // `firstCall` makes sure that local changes made during offline are reflected as server changes which the app is refreshed during offline mode
            var firstCall = true;
            // set state for pathVariables
            if (pathVariables && isWhat.isPlainObject(pathVariables)) {
                commit('SET_SYNCFILTERS', pathVariables);
                delete pathVariables.where;
                delete pathVariables.orderBy;
                commit('SET_PATHVARS', pathVariables);
            }
            var identifier = createFetchIdentifier({
                where: state._conf.sync.where,
                orderBy: state._conf.sync.orderBy,
                pathVariables: state._sync.pathVariables
            });
            if (isWhat.isFunction(state._sync.unsubscribe[identifier])) {
                var channelAlreadyOpenError = "openDBChannel was already called for these filters and pathvariables. Identifier: " + identifier;
                if (state._conf.logging) {
                    console.log(channelAlreadyOpenError);
                }
                return Promise.reject(channelAlreadyOpenError);
            }
            // getters.dbRef should already have pathVariables swapped out
            var dbRef = getters.dbRef;
            // apply where filters and orderBy
            if (getters.collectionMode) {
                getters.getWhereArrays().forEach(function (whereParams) {
                    dbRef = dbRef.where.apply(dbRef, whereParams);
                });
                if (state._conf.sync.orderBy.length) {
                    dbRef = dbRef.orderBy.apply(dbRef, state._conf.sync.orderBy);
                }
github mesqueeb / vuex-easy-firestore / src / utils / setDefaultValues.ts View on Github external
function convertTimestamps (originVal: any, targetVal: any): Date {
  if (originVal === '%convertTimestamp%') {
    // firestore timestamps
    // @ts-ignore
    if (isAnyObject(targetVal) && !isPlainObject(targetVal) && isFunction(targetVal.toDate)) {
      // @ts-ignore
      return targetVal.toDate()
    }
    // strings
    if (isString(targetVal) && isDate(new Date(targetVal))) {
      return new Date(targetVal)
    }
  }
  return targetVal
}
github mesqueeb / vuex-easy-firestore / test / setDefaultValues.js View on Github external
res = setDefaultValues(target, defaultValues)
  t.deepEqual(res, {
    body: nd,
    body2: {nd},
    dateStr2: new Date(dateStr2),
    firebase: {specialTS: { _ts: nd }}
  })
  t.deepEqual(defaultValues, {
    body: '%convertTimestamp%',
    body2: {nd: '%convertTimestamp%'},
    dateStr2: '%convertTimestamp%',
    firebase: {specialTS: { _ts: '%convertTimestamp%' }}
  })
  t.is(target.body, dateStr)
  t.deepEqual(target.body2, {nd})
  t.true(isFunction(target.firebase.specialTS._ts.toDate))
})
test('custom %convertTimestamp% defaultValue - delete %convertTimestamp%', async t => {
github mesqueeb / vuex-easy-firestore / src / module / actions.ts View on Github external
closeDBChannel ({getters, state, commit, dispatch}, { clearModule = false } = { clearModule: false }) {
      const identifier = createFetchIdentifier({
        where: state._conf.sync.where,
        orderBy: state._conf.sync.orderBy,
        pathVariables: state._sync.pathVariables
      })
      const unsubscribeDBChannel = state._sync.unsubscribe[identifier]
      if (isFunction(unsubscribeDBChannel)) {
        unsubscribeDBChannel()
        state._sync.streaming[identifier].resolve()
        state._sync.streaming[identifier] = null
        state._sync.unsubscribe[identifier] = null
      }
      if (clearModule) {
        commit('RESET_VUEX_EASY_FIRESTORE_STATE')
      }
    },
    set ({commit, dispatch, getters, state}, doc) {
github mesqueeb / vuex-easy-firestore / dist / index.cjs.js View on Github external
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;
            var identifier = createFetchIdentifier({
                where: state._conf.sync.where,
                orderBy: state._conf.sync.orderBy,
                pathVariables: state._sync.pathVariables
            });
            var unsubscribeDBChannel = state._sync.unsubscribe[identifier];
            if (isWhat.isFunction(unsubscribeDBChannel)) {
                unsubscribeDBChannel();
                state._sync.streaming[identifier].resolve();
                state._sync.streaming[identifier] = null;
                state._sync.unsubscribe[identifier] = null;
            }
            if (clearModule) {
                commit('RESET_VUEX_EASY_FIRESTORE_STATE');
            }
        },
        set: function (_a, doc) {
github mesqueeb / vuex-easy-firestore / dist / index.esm.js View on Github external
functionProps.forEach(function (prop) {
        var _prop = (syncProps.includes(prop))
            ? config.sync[prop]
            : config.serverChange[prop];
        if (!isFunction(_prop))
            errors.push("`" + prop + "` should be a Function, but is not.");
    });
    var objectProps = ['sync', 'serverChange', 'defaultValues', 'fetch'];
github mesqueeb / vuex-easy-firestore / dist / index.cjs.js View on Github external
.then(function (querySnapshot) {
                if (querySnapshot.done === true)
                    return querySnapshot;
                if (isWhat.isFunction(querySnapshot.forEach)) {
                    querySnapshot.forEach(function (_doc) {
                        var id = _doc.id;
                        var doc = getters.cleanUpRetrievedDoc(_doc.data(), id);
                        dispatch('applyHooksAndUpdateState', { change: 'added', id: id, doc: doc });
                    });
                }
                return querySnapshot;
            });
        },
github mesqueeb / vuex-easy-firestore / dist / index.esm.js View on Github external
Object.keys(state._sync.unsubscribe).forEach(function (unsubscribe) {
                if (isFunction(unsubscribe))
                    unsubscribe();
            });
            var self = this;
github mesqueeb / vuex-easy-firestore / dist / index.cjs.js View on Github external
functionProps.forEach(function (prop) {
        var _prop = (syncProps.includes(prop))
            ? config.sync[prop]
            : config.serverChange[prop];
        if (!isWhat.isFunction(_prop))
            errors.push("`" + prop + "` should be a Function, but is not.");
    });
    var objectProps = ['sync', 'serverChange', 'defaultValues', 'fetch'];

is-what

JS type check (TypeScript supported) functions like `isPlainObject() isArray()` etc. A simple & small integration.

MIT
Latest version published 10 days ago

Package Health Score

85 / 100
Full package analysis