Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import React from 'react';
import renderer from 'react-test-renderer';
import { Provider } from 'mobx-react';
import { types } from 'mobx-state-tree';
import Analytics from '..';
const Stores = types.model('Stores').props({
build: types.frozen({
isPwa: true,
channel: 'pwa',
packages: 'saturn-theme,wp-org-connection',
}),
connection: types.frozen({
selectedItem: { type: 'post', id: 60 },
}),
analytics: types.frozen({
customDimensions: () => ({
dimension1: 'dim1_post60',
dimension2: 'dim2_post60',
}),
googleAnalytics: {
ids: ['UA-12345678-1', 'UA-12345678-2'],
},
googleTagManager: {
ids: ['GTM-112233'],
clientProperties: {
anonymize: false,
siteId: 'site1122334455',
userIds: ['user00', 'user01'],
import { types } from 'mobx-state-tree';
export const WebhookCall = types.model('WebhookCall', {
id: types.identifier,
success: types.boolean,
request: types.frozen(),
response: types.frozen(),
});
IPatchRecorder,
createActionTrackingMiddleware2,
getEnv,
getRoot,
applyPatch,
flow,
addMiddleware,
addDisposer,
decorate,
isActionContextThisOrChildOf
} from "mobx-state-tree"
import { atomic } from "."
const Entry = types.model("UndoManagerEntry", {
patches: types.frozen>(),
inversePatches: types.frozen>()
})
const UndoManager = types
.model("UndoManager", {
history: types.array(Entry),
undoIdx: 0
})
.views(self => ({
get undoLevels() {
return self.undoIdx
},
get redoLevels() {
return self.history.length - self.undoIdx
},
get canUndo() {
return this.undoLevels > 0
type?: string;
}
export const DEFAULT_TYPE = 'string';
export const DEFAULT_GROUP_TITLE = 'Main';
export const SchemaField = types
.model('SchemaField', {
id: types.identifier,
type: types.string,
name: types.string,
title: types.string,
description: types.maybeNull(types.string),
primary: types.optional(types.boolean, false),
schemaId: types.maybeNull(types.string),
options: types.frozen(),
group: DEFAULT_GROUP_TITLE,
fields: types.maybeNull(types.array(types.late((): any => SchemaField))),
__typename: types.maybeNull(types.string),
})
.preProcessSnapshot(snapshot => ({
...snapshot,
fields: snapshot.fields || [],
}))
.views(self => ({
get isLeaf(): boolean {
return !hasParentOfType(self, SchemaField);
},
get defaultOptions() {
const settingsField = Settings.fields.find((f: any) => f.type === self.type);
if (settingsField) {
return settingsField.options;
isEmpty,
qsstringify
} from '../utils/helper';
import {Api, Payload, fetchOptions, Action} from '../types';
import qs from 'qs';
import pick = require('lodash/pick');
import {resolveVariableAndFilter} from '../utils/tpl-builtin';
class ServerError extends Error {
type = 'ServerError';
}
export const CRUDStore = ServiceStore.named('CRUDStore')
.props({
pristineQuery: types.optional(types.frozen(), {}),
query: types.optional(types.frozen(), {}),
prevPage: 1,
page: 1,
perPage: 10,
total: 0,
mode: 'normal',
hasNext: false,
selectedAction: types.frozen(),
items: types.optional(types.array(types.frozen()), []),
selectedItems: types.optional(types.array(types.frozen()), []),
unSelectedItems: types.optional(types.array(types.frozen()), []),
filterTogggable: false,
filterVisible: true,
hasInnerModalOpen: false
})
.views(self => ({
get lastPage() {
import {types} from 'mobx-state-tree';
import {replaceUrlParams} from './utils';
export const RouterStore = types
.model({
page: '',
path: '/',
params: types.frozen(),
queryParams: types.frozen(),
extra: types.frozen(),
options: types.frozen()
})
.views(self => ({
get currentUrl() {
return replaceUrlParams(self.path, self.params, self.queryParams);
}
}))
.actions(self => ({
openPage({id, path, extra: pageExtra}, params = {}, queryParams = {}, extra = {}) {
self.page = id;
self.path = path;
self.params = params;
self.queryParams = queryParams;
self.extra = {...pageExtra, ...extra};
}
* @property {function} setState
* @property {*} props
* @property {function} setPath
* @property {function} setOptions
* @property {function} setSelectMode
* @property {function} setSelectOptions
* @property {function} selectListener
* @property {function} selectHandler
* @property {function} setSelectListener
* @property {function} setSelectHandler
* @property {function} setSelect
*/
const FrameStore = types.model('FrameStore', {
state: types.optional(types.enumeration(['idle', 'pending', 'done', 'error']), 'idle'),
path: types.optional(types.string, ''),
options: types.frozen(),
selectMode: types.optional(types.boolean, false),
selectOptions: types.frozen(),
}).actions(self => {
return {
setState(value) {
self.state = value;
},
setPath(value) {
self.path = value;
},
setOptions(options) {
self.options = options;
},
setSelectMode(value) {
self.selectMode = value;
},
import { types, getRoot, flow } from "mobx-state-tree";
import { txStatus } from "../constants";
export const transactionInstance = types
.model({
hash: types.identifier,
receipt: types.optional(types.frozen(), {}),
interval: types.optional(types.frozen(), {}),
status: types.enumeration([
txStatus.PENDING,
txStatus.MINED,
txStatus.FAILED,
txStatus.SUCCESS
])
})
.actions(self => ({
addReceipt(_receipt) {
self.receipt = _receipt;
},
updateStatus(_status) {
if (self.status !== txStatus.FAILED && self.status !== txStatus.SUCCESS) {
self.status = _status;
}
import { getRoot, isValidReference, types } from 'mobx-state-tree'
import Resource from './Resource'
import createLocationCounts from '../helpers/createLocationCounts'
import subjectViewers from '../helpers/subjectViewers'
const Subject = types
.model('Subject', {
already_seen: types.optional(types.boolean, false),
favorite: types.optional(types.boolean, false),
finished_workflow: types.optional(types.boolean, false),
locations: types.frozen([]),
metadata: types.frozen({}),
retired: types.optional(types.boolean, false),
selected_at: types.maybe(types.string),
selection_state: types.maybe(types.string),
shouldDiscuss: types.maybe(types.frozen()),
user_has_finished_workflow: types.optional(types.boolean, false)
})
.actions(self => {
function addToCollection () {
const rootStore = getRoot(self)
rootStore.onAddToCollection(self.id)
}
function openInTalk (newTab = false) {
self.shouldDiscuss = {
import { types, getRoot, flow } from 'mobx-state-tree'
import { txStatus } from "../constants"
export const ContractInstance = types
.model({
name: types.identifier,
abi: types.frozen(),
txHash: types.frozen(),
address: types.string,
contract: types.optional(types.frozen(), {}),
methods: types.optional(types.frozen(), {}),
eventContract: types.optional(types.frozen(), {}),
events: types.optional(types.frozen(), {}),
})
.actions(self => ({
getMethod(_method) {
return self.methods[_method]
}
}))
export const transactionInstance = types
.model({
hash: types.identifier,