本文整理汇总了TypeScript中mobx-state-tree.types.maybeNull方法的典型用法代码示例。如果您正苦于以下问题:TypeScript types.maybeNull方法的具体用法?TypeScript types.maybeNull怎么用?TypeScript types.maybeNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mobx-state-tree.types
的用法示例。
在下文中一共展示了types.maybeNull方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
import { types } from 'mobx-state-tree';
export const Cast = types.model('Cast', {
id: types.identifier,
name: types.maybeNull(types.string),
pictureUrl: types.maybeNull(types.string),
});
示例2:
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),
title: types.maybeNull(types.string),
year: types.maybeNull(types.number),
summary: types.maybeNull(types.string),
runtime: types.maybeNull(types.number),
backdropUrl: types.maybeNull(types.string),
posterUrl: types.maybeNull(types.string),
示例3: updateDescription
import { types, flow } from 'mobx-state-tree';
import CodePush from 'react-native-code-push';
import VersionNumber from 'react-native-version-number';
import { UpdateMetadata } from './models/UpdateMetadata';
export const Update = types
.model('Update', {
updateMetadata: types.maybeNull(UpdateMetadata),
version: VersionNumber.appVersion,
build: VersionNumber.buildVersion,
})
.views(self => ({
get updateDescription() {
const { description = null } = self.updateMetadata || {};
return description;
},
get updateVersion() {
const { label = null } = self.updateMetadata || {};
return label;
},
get appVersion() {
return `${self.version || 'unknown'}${self.build ? ` (build ${self.build})` : ''}`;
},
}))
.actions(self => ({
update() {
return flow(function* () {
self.updateMetadata = yield CodePush.getUpdateMetadata();
})();
},
}))
示例4:
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;