本文整理汇总了TypeScript中mobx-state-tree.types.enumeration方法的典型用法代码示例。如果您正苦于以下问题:TypeScript types.enumeration方法的具体用法?TypeScript types.enumeration怎么用?TypeScript types.enumeration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mobx-state-tree.types
的用法示例。
在下文中一共展示了types.enumeration方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: switch
export const aclTypeValues = {
GROUP: { value: 'Group', text: 'Team' },
USER: { value: 'User', text: 'User' },
VIEWER: { value: 'Viewer', text: 'Everyone With Viewer Role' },
EDITOR: { value: 'Editor', text: 'Everyone With Editor Role' },
};
export const aclTypes = Object.keys(aclTypeValues).map(item => aclTypeValues[item]);
const defaultNewType = aclTypes[0].value;
export const NewPermissionsItem = types
.model('NewPermissionsItem', {
type: types.optional(
types.enumeration(Object.keys(aclTypeValues).map(item => aclTypeValues[item].value)),
defaultNewType
),
userId: types.maybe(types.number),
userLogin: types.maybe(types.string),
userAvatarUrl: types.maybe(types.string),
teamAvatarUrl: types.maybe(types.string),
teamId: types.maybe(types.number),
team: types.maybe(types.string),
permission: types.optional(types.number, 1),
})
.views(self => ({
isValid: () => {
switch (self.type) {
case aclTypeValues.GROUP.value:
return self.teamId && self.team;
示例2:
import { types } from 'mobx-state-tree';
export const Locale = types.enumeration('Locale', ['ICELANDIC']);
示例3:
import { mapMovie } from 'utils/mapMovie';
import { uniqBy } from 'lodash';
import Store from 'store';
import { isSameDay } from 'date-fns/esm';
import { addHours } from 'date-fns';
interface IMovieLocale {
contentRating?: string;
title?: string;
summary?: string;
alternateTitle?: string;
releaseDate?: string;
}
export const MovieStatus = types.enumeration('MovieStatus', [
'RELEASED',
'POST_PRODUCTION',
]);
export const MovieLocale = types.model('MovieLocale', {
id: types.identifier,
locale: Locale,
contentRating: types.maybeNull(types.string),
title: types.maybeNull(types.string),
summary: types.maybeNull(types.string),
alternateTitle: types.maybeNull(types.string),
releaseDate: types.maybeNull(types.string),
});
export const Movie = types.model('Movie', {
id: types.identifier,
isPartial: types.optional(types.boolean, true),
示例4:
import { types } from 'mobx-state-tree';
export const Gender = types.enumeration('Gender', [
'MALE',
'FEMALE',
'UNKNOWN',
]);
示例5:
import { types } from 'mobx-state-tree';
import { Cast } from './Cast';
const CreditType = types.enumeration('CreditType', [
'CAST',
'CREW',
]);
export const Credit = types.model('Credit', {
id: types.identifier,
cast: types.maybeNull(Cast),
role: types.maybe(types.string),
type: types.maybe(CreditType),
});
export type ICredit = typeof Credit.Type;
示例6:
export const Browsers = {
inApp: 'In-App',
default: Platform.select({ ios: 'Safari', android: 'Chrome' }),
};
export const Languages = {
en: 'English',
is: 'Ăslenska',
};
export const Themes = {
light: 'Light',
dark: 'Dark',
};
export const SortBy = types.enumeration('SortBy', Object.keys(SortBys));
export const Theme = types.enumeration('Theme', Object.keys(Themes));
export const Language = types.enumeration('Language', Object.keys(Languages));
export const Browser = types.enumeration('Browser', Object.keys(Browsers));
export const Settings = types.model('Settings', {
theme: types.optional(Theme, 'dark'),
language: types.optional(Language, 'en'),
promptOnExit: types.optional(types.boolean, true),
posterAnimation: types.optional(types.boolean, true),
hideSynopsis: types.optional(types.boolean, false),
hideCast: types.optional(types.boolean, false),
hideDaysOnScroll: types.optional(types.boolean, false),
useReaderMode: types.optional(types.boolean, false),
browser: types.optional(Browser, 'inApp'),
weekSortBy: types.optional(SortBy, 'popularity'),