当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript types.maybe方法代码示例

本文整理汇总了TypeScript中mobx-state-tree.types.maybe方法的典型用法代码示例。如果您正苦于以下问题:TypeScript types.maybe方法的具体用法?TypeScript types.maybe怎么用?TypeScript types.maybe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mobx-state-tree.types的用法示例。


在下文中一共展示了types.maybe方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: new

export function mstWithChildren<PROPS extends ModelProperties, OTHERS, TYPE>(
	Code: new() => TYPE,
	Data: IModelType<PROPS, OTHERS>,
	name?: string
) {
	const Children = types.array(types.late((): any => Model)) as IArrayType<
		RecursiveCreationType<PROPS>,
		RecursiveSnapshotType<PROPS>,
		TYPE
	>;
	const Branch = (Data as any as IModelType<PROPS, TYPE>).props({
		children: types.maybe(
			Children as any as IComplexType<
				RecursiveCreationType<PROPS>[],
				RecursiveSnapshotType<PROPS>[],
				IObservableArray<IModelType<PROPS, OTHERS>>
			>
		)
	});

	const Model = mst(Code, Branch, 'Node') as typeof Branch;

	return({ Model, Children });
}
开发者ID:ksjogo,项目名称:classy-mst,代码行数:24,代码来源:classy-mst.ts

示例2: setComponentId

import { types } from 'mobx-state-tree';

const UI = types
  .model('UI', {
    componentId: types.maybe(types.string),
    counter: types.optional(types.number, 0),
  })
  .actions(self => ({
    setComponentId(componentId?: string) {
      if (componentId) {
        self.componentId = componentId;
      }
    },
    increment() {
      self.counter += 1;
    },
  }));

export default UI;
开发者ID:birkir,项目名称:kvikmyndr-app,代码行数:19,代码来源:UI.ts

示例3: switch

  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;
        case aclTypeValues.USER.value:
          return !!self.userId && !!self.userLogin;
        case aclTypeValues.VIEWER.value:
开发者ID:zalando-zmon,项目名称:grafana,代码行数:31,代码来源:PermissionsStore.ts

示例4: Error

import _ from 'lodash';
import { types, getEnv } from 'mobx-state-tree';
import { NavItem } from './NavItem';
import { ITeam } from '../TeamsStore/TeamsStore';

export const NavStore = types
  .model('NavStore', {
    main: types.maybe(NavItem),
    node: types.maybe(NavItem),
  })
  .actions(self => ({
    load(...args) {
      let children = getEnv(self).navTree;
      let main, node;
      let parents = [];

      for (let id of args) {
        node = children.find(el => el.id === id);

        if (!node) {
          throw new Error(`NavItem with id ${id} not found`);
        }

        children = node.children;
        parents.push(node);
      }

      main = parents[parents.length - 2];

      if (main.children) {
        for (let item of main.children) {
开发者ID:cboggs,项目名称:grafana,代码行数:31,代码来源:NavStore.ts

示例5: updatePermission

ďťżimport { types } from 'mobx-state-tree';

export const PermissionsStoreItem = types
  .model('PermissionsStoreItem', {
    dashboardId: types.optional(types.number, -1),
    id: types.maybe(types.number),
    permission: types.number,
    permissionName: types.maybe(types.string),
    role: types.maybe(types.string),
    team: types.optional(types.string, ''),
    teamId: types.optional(types.number, 0),
    userEmail: types.optional(types.string, ''),
    userId: types.optional(types.number, 0),
    userLogin: types.optional(types.string, ''),
    inherited: types.maybe(types.boolean),
    sortRank: types.maybe(types.number),
    icon: types.maybe(types.string),
    nameHtml: types.maybe(types.string),
    sortName: types.maybe(types.string),
  })
  .actions(self => ({
    updateRole: role => {
      self.role = role;
    },
    updatePermission(permission: number, permissionName: string) {
      self.permission = permission;
      self.permissionName = permissionName;
    },
  }));
开发者ID:GPegel,项目名称:grafana,代码行数:29,代码来源:PermissionsStoreItem.ts

示例6: updatePermission

import { types } from 'mobx-state-tree';

export const PermissionsStoreItem = types
  .model('PermissionsStoreItem', {
    dashboardId: types.optional(types.number, -1),
    permission: types.number,
    permissionName: types.maybe(types.string),
    role: types.maybe(types.string),
    team: types.optional(types.string, ''),
    teamId: types.optional(types.number, 0),
    userEmail: types.optional(types.string, ''),
    userId: types.optional(types.number, 0),
    userLogin: types.optional(types.string, ''),
    inherited: types.maybe(types.boolean),
    sortRank: types.maybe(types.number),
    icon: types.maybe(types.string),
    name: types.maybe(types.string),
    teamAvatarUrl: types.maybe(types.string),
    userAvatarUrl: types.maybe(types.string),
  })
  .actions(self => ({
    updateRole: role => {
      self.role = role;
    },
    updatePermission(permission: number, permissionName: string) {
      self.permission = permission;
      self.permissionName = permissionName;
    },
  }));
开发者ID:cboggs,项目名称:grafana,代码行数:29,代码来源:PermissionsStoreItem.ts

示例7: flow

import { types, getEnv, flow } from 'mobx-state-tree';

export const Folder = types.model('Folder', {
  id: types.identifier(types.number),
  uid: types.string,
  title: types.string,
  url: types.string,
  canSave: types.boolean,
  hasChanged: types.boolean,
  version: types.number,
});

export const FolderStore = types
  .model('FolderStore', {
    folder: types.maybe(Folder),
  })
  .actions(self => ({
    load: flow(function* load(uid: string) {
      // clear folder state
      if (self.folder && self.folder.uid !== uid) {
        self.folder = null;
      }

      const backendSrv = getEnv(self).backendSrv;
      const res = yield backendSrv.getFolderByUid(uid);
      self.folder = Folder.create({
        id: res.id,
        uid: res.uid,
        title: res.title,
        url: res.url,
        canSave: res.canSave,
开发者ID:InvariantIO,项目名称:grafana,代码行数:31,代码来源:FolderStore.ts

示例8:

import { types } from 'mobx-state-tree';

export const Language = types.model('Language', {
  id: types.identifier,
  name: types.maybe(types.string),
});
开发者ID:birkir,项目名称:kvikmyndr-app,代码行数:6,代码来源:Language.ts

示例9: setName

import { types, IModelType, ISnapshottable } from "mobx-state-tree"
import { TestUserModel } from "./test-user-model"
import { IObservableArray } from "mobx"

// lol - https://github.com/Microsoft/TypeScript/issues/5938
export type __IModelType = IModelType<any, any>
export type __ISnapshottable = ISnapshottable<any>
export type __IObservableArray = IObservableArray<any>

export const TestCompanyModel = types
  .model()
  .props({
    name: "",
    employees: types.optional(types.array(TestUserModel), []),
    owner: types.maybe(TestUserModel),
  })
  .actions(self => ({
    setName(value: string) {
      self.name = value
    },
  }))

export const createTestCompany = () =>
  TestCompanyModel.create({
    name: "Steve",
    owner: { name: "me", age: 100 },
    employees: [{ name: "a", age: 1 }, { name: "b", age: 2 }],
  })
开发者ID:TheIdhem,项目名称:reactotron,代码行数:28,代码来源:test-company-model.ts

示例10: disabled

import { types } from 'mobx-state-tree';
import { CinemaReference } from '../cinemas';
import store from '../index';
import { utcToZonedTime, toDate } from 'date-fns-tz';
import { addHours } from 'date-fns';

export const Showtime = types.model('Showtime', {
  id: types.identifier,
  playingAt: types.Date,
  cinema: types.maybe(CinemaReference),
  room: types.maybe(types.string),
  ticketUrl: types.maybe(types.string),
  flags: types.array(types.string),
})
.preProcessSnapshot((snapshot) => {
  const date = utcToZonedTime(snapshot.playingAt || 0, 'America/New_York');
  return {
    ...snapshot,
    playingAt: toDate(date, { timeZone: 'GMT' }),
  };
})
.views(self => ({
  get disabled() {
    const timeInIceland = utcToZonedTime(Date.now(), 'GMT');
    if (self.playingAt) {
      return self.playingAt.getTime() < timeInIceland.getTime();
    }
    return false;
  },
}));
开发者ID:birkir,项目名称:kvikmyndr-app,代码行数:30,代码来源:Showtime.ts


注:本文中的mobx-state-tree.types.maybe方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。