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


TypeScript types.map方法代码示例

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


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

示例1: test

test("can time travel with Mutable object", t => {
    const MutableUnion = types.union(
        types.string,
        types.boolean,
        types.number,
        types.map(types.late(() => MutableUnion)),
        types.array(types.late(() => MutableUnion))
    )
    const MutableStoreModel = types
        .model({
            mutable: MutableUnion
        })
        .actions(self => {
            setUndoManagerDifferentTree(self)
            return {
                setProp(k, v) {
                    self.mutable.set(k, v)
                }
            }
        })
    const store = MutableStoreModel.create({ mutable: {} })
    const mutable = store.mutable

    t.deepEqual(mutable.toJSON(), {})
    t.is(undoManager.canUndo, false)
    t.is(undoManager.canRedo, false)
    t.is(undoManager.history.length, 0)

    store.setProp("foo", 1)
    t.deepEqual(mutable.toJSON(), { foo: 1 })
    t.is(undoManager.canUndo, true)
    t.is(undoManager.canRedo, false)
    t.is(undoManager.history.length, 1)

    store.setProp("foo", {})
    t.deepEqual(mutable.toJSON(), { foo: {} })
    t.is(undoManager.canUndo, true)
    t.is(undoManager.canRedo, false)
    t.is(undoManager.history.length, 2)

    undoManager.undo()
    t.deepEqual(mutable.toJSON(), { foo: 1 })
    t.is(undoManager.canUndo, true)
    t.is(undoManager.canRedo, true)
    t.is(undoManager.history.length, 2)

    undoManager.undo()
    t.deepEqual(mutable.toJSON(), {})
    t.is(undoManager.canUndo, false)
    t.is(undoManager.canRedo, true)
    t.is(undoManager.history.length, 2)
})
开发者ID:lelandyolo,项目名称:mobx-state-tree,代码行数:52,代码来源:UndoManager.ts

示例2: all

// Dependencies
import { flow, types } from 'mobx-state-tree'
import * as api from './api'

// Model
const Item = types.model('Item', {
  id: types.number,
  name: types.string
})

// Store
const ItemsStore = types
  .model('ItemsStore', {
    _cache: types.map(Item)
  })
  .actions(self => {
    const fetchItems = flow(function*() {
      const items: Array<typeof Item.Type> = yield api.getItems()

      items.forEach(item => self._cache.set(item.id.toString(), item))
    })

    return {
      fetchItems
    }
  })
  .views(self => ({
    get all() {
      return Array.from(self._cache.values())
    }
  }))
开发者ID:chaucerbao,项目名称:react-project-template,代码行数:31,代码来源:items.ts

示例3: filteredMembers

  groupId: types.identifier(types.string),
  teamId: types.number,
});

type TeamGroupType = typeof TeamGroup.Type;
export interface ITeamGroup extends TeamGroupType {}

export const Team = types
  .model('Team', {
    id: types.identifier(types.number),
    name: types.string,
    avatarUrl: types.string,
    email: types.string,
    memberCount: types.number,
    search: types.optional(types.string, ''),
    members: types.optional(types.map(TeamMember), {}),
    groups: types.optional(types.map(TeamGroup), {}),
  })
  .views(self => ({
    get filteredMembers() {
      let members = this.members.values();
      let regex = new RegExp(self.search, 'i');
      return members.filter(member => {
        return regex.test(member.login) || regex.test(member.email);
      });
    },
  }))
  .actions(self => ({
    setName(name: string) {
      self.name = name;
    },
开发者ID:cboggs,项目名称:grafana,代码行数:31,代码来源:TeamsStore.ts

示例4: currentUrl

import { types } from 'mobx-state-tree';
import { toJS } from 'mobx';
import { toUrlParams } from 'app/core/utils/url';

const QueryInnerValueType = types.union(types.string, types.boolean, types.number);
const QueryValueType = types.union(QueryInnerValueType, types.array(QueryInnerValueType));

export const ViewStore = types
  .model({
    path: types.string,
    query: types.map(QueryValueType),
    routeParams: types.map(QueryValueType),
  })
  .views(self => ({
    get currentUrl() {
      let path = self.path;

      if (self.query.size) {
        path += '?' + toUrlParams(toJS(self.query));
      }
      return path;
    },
  }))
  .actions(self => {
    // querystring only
    function updateQuery(query: any) {
      self.query.clear();
      for (let key of Object.keys(query)) {
        if (query[key]) {
          self.query.set(key, query[key]);
        }
开发者ID:cboggs,项目名称:grafana,代码行数:31,代码来源:ViewStore.ts

示例5: get

  id: string;
  showtimes: IShowtimeFromDb[];
}

export const InTheaters = types.model('InTheaters', {
  loading: false,
  loaded: false,
  isOffline: false,
  isCache: false,
  dates: types.map(types.model('DateOfMovies', {
    date: types.identifier,
    movies: types.map(types.model('MovieRef', {
      id: types.identifier,
      movie: types.reference(Movie, {
        get(identifier: string) {
          return Movies.movies.get(identifier) as typeof Movie.Type;
        },
        set(value: typeof Movie.Type) {
          return value.id;
        },
      }),
    })),
  })),
})
.views(self => ({
  moviesForDate(date: Date) {
    const movies = self.dates.get(date.toISOString().substr(0, 10));
    if (movies) {
      return Array.from(movies.movies.values());
    }
    return [];
  },
开发者ID:birkir,项目名称:kvikmyndr-app,代码行数:32,代码来源:in-theaters.ts

示例6: get

import { client } from '../services/graphql.service';
import { Cinema } from './models/Cinema';
import fetchCinemaByIdQuery from '../queries/fetchCinemaById.gql';
import fetchAllCinemas from '../queries/fetchAllCinemas.gql';

export const CinemaReference = types.reference(Cinema, {
  get(identifier: string) {
    return Cinemas.getOrLoadById(identifier) as typeof Cinema.Type || [];
  },
  set(value: typeof Cinema.Type) {
    return value.id;
  },
});

export const Cinemas = types.model('Cinemas', {
  cinemas: types.map(Cinema),
})
.actions((self) => {

  const addCinema = (obj: any) => {
    const cinema = { ...obj };
    if (self.cinemas.has(cinema.id)) {
      return;
    }

    return self.cinemas.put(
      Cinema.create(cinema),
    );
  };

  const loadAllCinemas = flow(function* () {
开发者ID:birkir,项目名称:kvikmyndr-app,代码行数:31,代码来源:cinemas.ts

示例7: currentUrl

import { types } from 'mobx-state-tree';
import { toJS } from 'mobx';
import { toUrlParams } from 'app/core/utils/url';

const QueryInnerValueType = types.union(types.string, types.boolean, types.number);
const QueryValueType = types.union(QueryInnerValueType, types.array(QueryInnerValueType));

export const ViewStore = types
  .model({
    path: types.string,
    query: types.map(QueryValueType),
  })
  .views(self => ({
    get currentUrl() {
      let path = self.path;

      if (self.query.size) {
        path += '?' + toUrlParams(toJS(self.query));
      }
      return path;
    },
  }))
  .actions(self => {
    function updateQuery(query: any) {
      self.query.clear();
      for (let key of Object.keys(query)) {
        self.query.set(key, query[key]);
      }
    }

    function updatePathAndQuery(path: string, query: any) {
开发者ID:xiequanqin,项目名称:grafana,代码行数:31,代码来源:ViewStore.ts

示例8: all

import { types } from 'mobx-state-tree'
import { values as mobxValues } from 'mobx'

const User = types.model('User', {
  id: types.identifier,
  nick: '',
  status: ''
})

export const Users = types
  .model('Users', {
    items: types.optional(types.map(User), {})
  })
  .actions(self => {
    const set = items => {
      self.items = items
    }
    return { set }
  })
  .views(self => {
    return {
      get all() {
        return mobxValues(self.items)
      }
    }
  })
开发者ID:NotBadDevs,项目名称:minesweepers,代码行数:26,代码来源:users.ts

示例9: return

import { types, flow } from 'mobx-state-tree';
import { Movie } from './models/Movie';
import { client } from '../services/graphql.service';
import fetchMovieByIdQuery from '../queries/fetchMovieById.gql';
import fetchNewMoviesQuery from '../queries/fetchNewMovies.gql';
import { addDays } from 'date-fns';
import { mapMovie } from 'utils/mapMovie';
import { FetchPolicy } from 'apollo-boost';

export const Movies = types.model('Movies', {
  movies: types.map(Movie),
  comingSoon: types.array(types.reference(Movie)),
  isOffline: false,
  isCache: false,
})
.actions(self => ({
  addPartialMovie: (obj: any) => {
    return (self as any).addMovie(obj, true);
  },
  addMovie: (obj: any, isPartial: boolean) => {
    if (self.movies.has(obj.id)) {
      const movie = self.movies.get(obj.id);
      return movie!.update(obj, isPartial);
    }

    return self.movies.put(
      Movie.create(mapMovie(obj, isPartial)),
    );
  },
  loadMovieById: flow(function* loadMovieById(movieId: string) {
    const start = new Date();
开发者ID:birkir,项目名称:kvikmyndr-app,代码行数:31,代码来源:movies.ts

示例10: get

import { client } from '../services/graphql.service';
import { Genre } from './models/Genre';
import fetchGenreByIdQuery from '../queries/fetchGenreById.gql';
import fetchAllGenres from '../queries/fetchAllGenres.gql';

export const GenreReference = types.reference(Genre, {
  get(identifier: string) {
    return Genres.getOrLoadById(identifier) as typeof Genre.Type || [];
  },
  set(value: typeof Genre.Type) {
    return value.id;
  },
});

export const Genres = types.model('Genres', {
  genres: types.map(Genre),
})
.actions((self) => {

  const addGenre = (obj: any) => {
    const genre = { ...obj };
    if (self.genres.has(genre.id)) {
      return;
    }

    return self.genres.put(
      Genre.create(genre),
    );
  };

  const loadAllGenres = flow(function* () {
开发者ID:birkir,项目名称:kvikmyndr-app,代码行数:31,代码来源:genres.ts


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