Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const oneLimit = promiseLimit(1);
const defaultOptions = {
sortByList: [{by: 'quality'}]
};
const optionModelMap = {
sortByList: types.frozen,
};
const optionsKeys = Object.keys(defaultOptions);
const optionsModel = types.model('optionsModel', Object.assign({
state: types.optional(types.string, 'idle'), // idle, loading, ready, error
options: types.optional(types.model(optionsKeys.reduce((obj, key) => {
obj[key] = optionModelMap[key];
return obj;
}, {})), {}),
})).actions(self => {
return {
assign(obj) {
Object.assign(self, obj);
},
set(key, value) {
self.options[key] = value;
return self.save();
},
get(key) {
return self.options[key];
}
};
import { types as t } from 'mobx-state-tree'
import { PAGE_SIZE } from '@config'
// NOTE: the SimpleXXX version is to avoid circle import issue which cause MST error
const SimpleCommunity = t.model('SimpleCommunity', {
id: t.maybeNull(t.string),
title: t.maybeNull(t.string),
desc: t.optional(t.string, ''),
raw: t.maybeNull(t.string),
logo: t.maybeNull(t.string),
})
const SimpleUser = t.model('SimpleUser', {
id: t.maybeNull(t.string),
nickname: t.maybeNull(t.string),
bio: t.maybeNull(t.string),
avatar: t.maybeNull(t.string),
})
export const Category = t.model('Category', {
id: t.maybeNull(t.string),
/*
* CommunityBannerStore store
*
*/
import { types as t, getParent } from 'mobx-state-tree'
// import R from 'ramda'
import { markStates, buildLog } from '@utils'
/* eslint-disable no-unused-vars */
const log = buildLog('S:CommunityBannerStore')
/* eslint-enable no-unused-vars */
const CommunityBannerStore = t
.model('CommunityBannerStore', {
// postsTotalCount: t.optional(t.number, 0),
filteredPostsCount: t.maybeNull(t.number),
filteredJobsCount: t.maybeNull(t.number),
filteredVideosCount: t.maybeNull(t.number),
filteredReposCount: t.maybeNull(t.number),
// tagsTotalCount: t.optional(t.number, 0),
})
.views(self => ({
get root() {
return getParent(self)
},
get postsTotalCount() {
return self.root.communityContent.pagedPosts.totalCount
},
get jobsTotalCount() {
selected_at: types.maybe(types.string),
selection_state: types.maybe(types.string),
user_has_finished_workflow: types.optional(types.boolean, false)
}),
subject_flagged: types.optional(types.boolean, false),
userAgent: types.optional(types.string, navigator.userAgent),
userLanguage: types.string,
utcOffset: types.optional(types.string, ((new Date()).getTimezoneOffset() * 60).toString()),
viewport: types.frozen({
height: types.optional(types.integer, window.innerHeight),
width: types.optional(types.integer, window.innerWidth)
}),
workflowVersion: types.string
})
const Classification = types
.model('Classification', {
annotations: types.map(types.union(...annotationModels)),
completed: types.optional(types.boolean, false),
links: types.frozen({
project: types.string,
subjects: types.array(types.string),
workflow: types.string
}),
metadata: types.maybe(ClassificationMetadata)
})
export { ClassificationMetadata }
export default types.compose('ClassificationResource', Resource, AnnotationsStore, Classification)
delete result[key];
}
});
return result;
}
};
});
/**
* @typedef {{}} CodeAuthStore
* @property {string} [url]
* @property {ElementSelectorStore|undefined} loginForm
* @property {function} set
* @property {function} getSnapshot
*/
const CodeAuthStore = types.model('CodeAuthStore', {
url: types.optional(types.string, ''),
loginForm: types.maybe(ElementSelectorStore),
}).actions(self => {
return {
set(key, value) {
self[key] = value;
},
};
}).views((self) => {
return {
getSnapshot() {
const result = getSnapshot(self);
if (!result.url) {
delete result.url;
}
if (result.loginForm && !result.loginForm.selector) {
import { DTOs } from '../../../utils/eShop.dtos';
export { TypeType, TypeModel };
const debug = new Debug('catalog types');
export interface TypeListType {
entries: Map;
loading: boolean;
list: (term?: string, id?: string) => Promise<{}>;
add: (type: TypeType) => void;
remove: (id: string) => Promise<{}>;
clear(): void;
readonly projection: { id: string, label: string}[];
}
export const TypeListModel = types
.model('Catalog_Type_List', {
entries: types.optional(types.map(TypeModel), {}),
loading: types.optional(types.boolean, true)
})
.views(self => ({
get projection() {
return Array.from(self.entries.values()).map(x => ({ id: x.id, label: x.type }));
}
}))
.actions(self => {
const list = flow(function*(term?: string, id?: string) {
const request = new DTOs.ListCatalogTypes();
request.term = term;
request.id = id;
import { flow, Instance, types } from 'mobx-state-tree';
const cmp = (fn: (x: T) => U) => (a: T, b: T): number =>
fn(a) > fn(b) ? 1 : -1;
const User = types.model({
email: types.string,
gender: types.enumeration(['male', 'female']),
id: types.identifier,
name: types.model({
first: types.string,
last: types.string
}),
picture: types.model({
large: types.string
})
});
const Store = types
.model({
users: types.array(User),
usersOrder: types.enumeration(['name', 'id'])
})
.views(self => ({
getSortedUsers() {
if (self.usersOrder === 'name')
import _ from "lodash"
import { types, getParent } from "mobx-state-tree"
import Track, { parse as parseTrack } from "store/track"
export default types
.model("Album", {
id: types.identifier,
title: types.string,
artistName: types.string,
year: types.maybeNull(types.number),
userRating: types.optional(types.number, 0),
addedAt: types.number,
playCount: types.optional(types.number, 0),
thumb: types.maybeNull(types.string),
tag: types.array(types.string),
genres: types.array(types.string),
studio: types.maybeNull(types.string),
tracks: types.optional(types.array(Track), []),
})
.views((self) => ({
})
.views(self => ({
getAssignee() {
if (!this.assignee) return undefined;
return getRoot(self).users.get(this.assignee);
},
}))
.actions(self => ({
setAssignee(user) {
if (typeof user === 'string') this.assignee = user;
else if (User.is(user)) this.assignee = user.userid;
else throw new Error('Not a valid user object or user id');
},
}));
const App = types.model('App', {
todos: types.array(Todo),
users: types.map(User),
});
const app = App.create({
todos: [
{
title: 'Learn MST',
done: false,
assignee: '37',
},
],
users: {
'37': {
userid: '37',
name: 'Michel Weststrate',
paymentUsage: t.string,
state: t.string,
amount: t.number,
note: t.optional(t.string, ''),
insertedAt: t.optional(t.string, ''),
})
const PagedBillRecords = t.model('PagedBillRecords', {
entries: t.optional(t.array(Bill), []),
pageNumber: t.optional(t.number, 1),
pageSize: t.optional(t.number, PAGE_SIZE.D),
totalCount: t.optional(t.number, 0),
totalPages: t.optional(t.number, 0),
})
const UserBilling = t
.model('UserBilling', {
pagedBillRecords: t.optional(PagedBillRecords, emptyPagiData),
})
.views(self => ({
get root() {
return getParent(self)
},
get pagedBillRecordsData() {
return stripMobx(self.pagedBillRecords)
},
get accountInfo() {
return self.root.accountInfo
},
get isSelfViewing() {
return self.root.viewing.isSelfViewing
},