當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript react-plugin.createPlugin函數代碼示例

本文整理匯總了TypeScript中react-plugin.createPlugin函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript createPlugin函數的具體用法?TypeScript createPlugin怎麽用?TypeScript createPlugin使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了createPlugin函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getNewPluginName

export function getMethodsOf<Spec extends PluginSpec>(
  pluginName: Spec['name']
) {
  const name = getNewPluginName();
  createPlugin({ name }).register();

  return getPluginContext(name).getMethodsOf<Spec>(pluginName);
}
開發者ID:skidding,項目名稱:cosmos,代碼行數:8,代碼來源:plugin.ts

示例2: mockPlug

export function mockPlug(
  slotName: string,
  component: PlugComponentType<any, any>
) {
  const name = getNewPluginName();
  const testPlugin = createPlugin({ name });
  testPlugin.plug(slotName, component);
  testPlugin.register();
}
開發者ID:skidding,項目名稱:cosmos,代碼行數:9,代碼來源:plugin.ts

示例3: onServerMessage

import { createPlugin, PluginContext } from 'react-plugin';
import { Message } from 'react-cosmos-shared2/util';
import { BuildMessage } from 'react-cosmos-shared2/build';
import { MessageHandlerSpec } from './../MessageHandler/public';
import { NotificationsSpec } from './../Notifications/public';
import { BuildNotificationsSpec } from './public';

type Context = PluginContext<BuildNotificationsSpec>;

const { on, register } = createPlugin<BuildNotificationsSpec>({
  name: 'buildNotifications'
});

on<MessageHandlerSpec>('messageHandler', {
  serverMessage: onServerMessage
});

export { register };

function onServerMessage(context: Context, msg: Message) {
  const { getMethodsOf } = context;
  const notifications = getMethodsOf<NotificationsSpec>('notifications');

  const buildMsg = msg as BuildMessage;
  switch (buildMsg.type) {
    case 'buildStart':
      return notifications.pushStickyNotification({
        id: 'build',
        type: 'loading',
        title: 'Rebuilding...',
        info: 'Your code is updating.'
開發者ID:skidding,項目名稱:cosmos,代碼行數:31,代碼來源:index.ts

示例4: getConnectedRendererIds

import { setFixtureState } from './setFixtureState';
import { receiveResponse } from './receiveResponse';
import { onRouterFixtureChange } from './onRouterFixtureChange';
import { RendererCoreSpec } from './public';
import { Context } from './shared';

const { on, register } = createPlugin<RendererCoreSpec>({
  name: 'rendererCore',
  initialState: {
    connectedRendererIds: [],
    primaryRendererId: null,
    fixtures: {},
    fixtureState: {}
  },
  methods: {
    getConnectedRendererIds,
    getPrimaryRendererId,
    getFixtures,
    getFixtureState,
    isRendererConnected,
    isValidFixtureSelected,
    setFixtureState,
    selectPrimaryRenderer,
    receiveResponse
  }
});

on<RouterSpec>('router', { fixtureChange: onRouterFixtureChange });

export { register };

function getConnectedRendererIds({ getState }: Context) {
開發者ID:skidding,項目名稱:cosmos,代碼行數:32,代碼來源:index.ts

示例5: onRendererResponse

import { createPlugin, PluginContext } from 'react-plugin';
import { Message } from 'react-cosmos-shared2/util';
import { WebpackRendererResponse } from 'react-cosmos-shared2/webpack';
import { RendererCoreSpec } from './../RendererCore/public';
import { NotificationsSpec } from './../Notifications/public';
import { WebpackHmrNotificationSpec } from './public';

type Context = PluginContext<WebpackHmrNotificationSpec>;

const { on, register } = createPlugin<WebpackHmrNotificationSpec>({
  name: 'webpackHmrNotification'
});

on<RendererCoreSpec>('rendererCore', {
  response: onRendererResponse
});

export { register };

function onRendererResponse(context: Context, msg: Message) {
  const { getMethodsOf } = context;
  const notifications = getMethodsOf<NotificationsSpec>('notifications');

  const rendererResponse = msg as WebpackRendererResponse;
  switch (rendererResponse.type) {
    case 'rendererHmrFail':
      notifications.pushTimedNotification({
        // This event could potentially be triggered by multiple renderers at
        // once, but it only makes sense that hot reloading should fail the same
        // in all of them. To prevent duplicating this error in such cases the
        // notification ID is _not_ unique per renderer.
開發者ID:skidding,項目名稱:cosmos,代碼行數:31,代碼來源:index.ts

示例6: subscribeToLocationChanges

import {
  UrlParams,
  getUrlParams,
  pushUrlParams,
  subscribeToLocationChanges
} from '../../shared/url';
import { RouterSpec } from './public';

type Context = PluginContext<RouterSpec>;

const { onLoad, register } = createPlugin<RouterSpec>({
  name: 'router',
  initialState: {
    urlParams: {}
  },
  methods: {
    getSelectedFixtureId,
    isFullScreen,
    selectFixture,
    unselectFixture
  }
});

onLoad(context => {
  const { setState } = context;
  setState({ urlParams: getUrlParams() });

  return subscribeToLocationChanges((urlParams: UrlParams) => {
    const { fixtureId } = context.getState().urlParams;
    const fixtureChanged = !isEqual(urlParams.fixtureId, fixtureId);

    setState({ urlParams }, () => {
開發者ID:skidding,項目名稱:cosmos,代碼行數:32,代碼來源:index.ts

示例7: loadCache

import * as localForage from 'localforage';
import { PluginContext, createPlugin } from 'react-plugin';
import { StorageSpec } from './public';

type Context = PluginContext<StorageSpec>;

const { register } = createPlugin<StorageSpec>({
  name: 'storage',
  initialState: {
    cache: null
  },
  methods: {
    loadCache,
    getItem,
    setItem
  }
});

export { register };

async function loadCache(context: Context, projectId: string) {
  const items = (await localForage.getItem(getProjectKey(projectId))) || {};
  context.setState({ cache: { projectId, items } });
}

function getItem(context: Context, key: string) {
  const { cache } = context.getState();
  if (!cache) {
    throw new Error(`Can't retrieve item "${key}" before loading storage`);
  }
開發者ID:skidding,項目名稱:cosmos,代碼行數:30,代碼來源:index.ts

示例8:

export function mockMethodsOf<Spec extends PluginSpec>(
  pluginName: Spec['name'],
  methods: Partial<MethodHandlers<Spec>>
) {
  createPlugin<any>({ name: pluginName, methods }).register();
}
開發者ID:skidding,項目名稱:cosmos,代碼行數:6,代碼來源:plugin.ts


注:本文中的react-plugin.createPlugin函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。