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


TypeScript reflux.createStore函数代码示例

本文整理汇总了TypeScript中reflux.createStore函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createStore函数的具体用法?TypeScript createStore怎么用?TypeScript createStore使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: create

/**
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

import * as Reflux from 'reflux';
import events from '../../events';
import _UnitFrame from './_UnitFrame';

const FriendlyTargetStore = {
  create() {
    const actions = Reflux.createActions(['start', 'stop']);
    const store = Reflux.createStore({
      mixins: [_UnitFrame],
      topic: events.clientEventTopics.handlesFriendlyTarget,
      listenables: actions
    });
    return {
      store: store,
      actions: actions
    };
  }
};

export default FriendlyTargetStore;
开发者ID:Fidaman,项目名称:Camelot-Unchained,代码行数:26,代码来源:FriendlyTargetStore.ts

示例2: Builder

const WidgetsStore = Reflux.createStore({
    listenables: [WidgetsActions],
    _deserializeWidget(widget: SerializedWidget): Widget {
        return {
            id: widget.id,
            title: widget.description,
            type: widget.type,
            cacheTime: widget.cache_time,
            creatorUserId: widget.creator_user_id,
            config: widget.config
        };
    },
    _serializeWidget(widget: Widget): SerializedWidget {
        return {
            id: widget.id,
            description: widget.title,
            type: widget.type,
            cache_time: widget.cacheTime,
            creator_user_id: widget.creatorUserId,
            config: widget.config
        };
    },
    _serializeWidgetForUpdate(widget: Widget): any {
        return {
            description: widget.title,
            type: widget.type,
            cache_time: widget.cacheTime,
            creator_user_id: widget.creatorUserId,
            config: widget.config,
        };
    },

    addWidget(dashboardId: string, widgetType: string, widgetTitle: string, widgetConfig: Object): Promise<string[]> {
        var widgetData = {description: widgetTitle, type: widgetType, config: widgetConfig};
        var url = URLUtils.qualifyUrl(jsRoutes.controllers.api.DashboardsApiController.addWidget(dashboardId).url);
        var promise = fetch('POST', url, widgetData);

        promise.then(() => UserNotification.success("Widget created successfully"),
        (error) => {
            if (error.additional.status !== 404) {
                UserNotification.error("Creating widget failed with status: " + error,
                    "Could not create widget");
            }
        });

        return promise;
    },

    loadWidget(dashboardId: string, widgetId: string): Promise<string[]> {
        var url = URLUtils.qualifyUrl(jsRoutes.controllers.api.DashboardsApiController.widget(dashboardId, widgetId).url);
        const promise = new Builder('GET', url)
            .authenticated()
            .setHeader('X-Graylog2-No-Session-Extension', 'true')
            .json()
            .build();

        promise.catch((error) => {
            if (error.additional.status !== 404) {
                UserNotification.error("Loading widget information failed with status: " + error,
                    "Could not load widget information");
            }
        });
        return promise.then((widget) => this._deserializeWidget(widget));
    },

    updateWidget(dashboardId: string, widget: Widget): Promise<string[]> {
        var url = URLUtils.qualifyUrl(jsRoutes.controllers.api.DashboardsApiController.updateWidget(dashboardId, widget.id).url);
        var promise = fetch('PUT', url, this._serializeWidgetForUpdate(widget));

        promise.then(() => UserNotification.success("Widget updated successfully"),
        (error) => {
            UserNotification.error("Updating widget \"" + widget.title + "\" failed with status: " + error.message,
                "Could not update widget");
        });

        return promise;
    },

    loadValue(dashboardId: string, widgetId: string, resolution: number): Promise<string[]> {
        var url = URLUtils.qualifyUrl(jsRoutes.controllers.api.DashboardsApiController.widgetValue(dashboardId, widgetId, resolution).url);

        return new Builder('GET', url)
            .authenticated()
            .setHeader('X-Graylog2-No-Session-Extension', 'true')
            .json()
            .build();
    },

    removeWidget(dashboardId: string, widgetId: string): Promise<string[]> {
        const url = URLUtils.qualifyUrl(jsRoutes.controllers.api.DashboardsApiController.removeWidget(dashboardId, widgetId).url);

        const promise = fetch('DELETE', url).then(() => {
            this.trigger({delete: widgetId});
        });
        WidgetsActions.removeWidget.promise(promise);

        return promise;
    },
});
开发者ID:Graylog2,项目名称:graylog2-web-interface,代码行数:99,代码来源:WidgetsStore.ts

示例3: fetchPeriodically

const WidgetsStore = Reflux.createStore({
    listenables: [WidgetsActions],
    _serializeWidgetForUpdate(widget: Widget): any {
        return {
            description: widget.description,
            type: widget.type,
            cache_time: widget.cache_time,
            creator_user_id: widget.creator_user_id,
            config: widget.config,
        };
    },

    addWidget(dashboardId: string, widgetType: string, widgetTitle: string, widgetConfig: Object): Promise<string[]> {
        var widgetData = {description: widgetTitle, type: widgetType, config: widgetConfig};
        var url = URLUtils.qualifyUrl(ApiRoutes.DashboardsApiController.addWidget(dashboardId).url);
        var promise = fetch('POST', url, widgetData);

        promise.then(
          response => {
              UserNotification.success("Widget created successfully");
              return response;
          },
          error => {
              if (error.additional.status !== 404) {
                  UserNotification.error("Creating widget failed with status: " + error,
                    "Could not create widget");
              }
          });

        return promise;
    },

    loadWidget(dashboardId: string, widgetId: string): Promise<string[]> {
        var url = URLUtils.qualifyUrl(ApiRoutes.DashboardsApiController.widget(dashboardId, widgetId).url);
        const promise = fetchPeriodically('GET', url);

        promise.catch((error) => {
            if (error.additional.status !== 404) {
                UserNotification.error("Loading widget information failed with status: " + error,
                    "Could not load widget information");
            }
        });
        return promise;
    },

    updateWidget(dashboardId: string, widget: Widget): Promise<string[]> {
        var url = URLUtils.qualifyUrl(ApiRoutes.DashboardsApiController.updateWidget(dashboardId, widget.id).url);
        var promise = fetch('PUT', url, this._serializeWidgetForUpdate(widget));

        promise.then(
          response => {
              UserNotification.success("Widget updated successfully");
              return response;
          },
          error => {
              UserNotification.error("Updating widget \"" + widget.description + "\" failed with status: " + error.message,
                "Could not update widget");
          }
        );

        return promise;
    },

    loadValue(dashboardId: string, widgetId: string, resolution: number): Promise<string[]> {
        var url = URLUtils.qualifyUrl(ApiRoutes.DashboardsApiController.widgetValue(dashboardId, widgetId, resolution).url);

        return fetchPeriodically('GET', url);
    },

    removeWidget(dashboardId: string, widgetId: string): Promise<string[]> {
        const url = URLUtils.qualifyUrl(ApiRoutes.DashboardsApiController.removeWidget(dashboardId, widgetId).url);

        const promise = fetch('DELETE', url).then(response => {
            this.trigger({delete: widgetId});
            return response;
        });
        WidgetsActions.removeWidget.promise(promise);

        return promise;
    },
});
开发者ID:Graylog2,项目名称:graylog2-server,代码行数:81,代码来源:WidgetsStore.ts

示例4: init

    const store = Reflux.createStore({
      topic: events.clientEventTopics.handlesControlGameScore,
      listenables: actions,
      init() {
        // Initialise the store is basic info.  This is so that React components
        // can use the Store to initialise their state in getDefaultState().
        this.info = {

        };
      },
      start() {
        const store = this;

        // If this store has already been started, then ingore subsequent start
        // request
        if (this.started) return;
        this.started = true;

        // Listen to the event group for this unit frame
        events.on(this.topic, (controlGameScore: any) => {

          // Update store info
          store.info = controlGameScore;

          // Trigger changed notification for this store
          store.trigger(store.info);
        });
      },
      stop() {
        // TODO
      }
    });
开发者ID:Fidaman,项目名称:Camelot-Unchained,代码行数:32,代码来源:ControlGameScoreStore.ts

示例5: create

/**
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

import * as Reflux from 'reflux';
import events from '../../events/events';
import _UnitFrame from './_UnitFrame';

const EnemyTargetStore = {
  create() {
    const actions = Reflux.createActions(['start', 'stop']);
    const store = Reflux.createStore({
      mixins: [_UnitFrame],
      handles: events.handlesEnemyTarget,
      listenables: actions
    });
    return {
      store: store,
      actions: actions
    };
  }
};

export default EnemyTargetStore;
开发者ID:Fidaman,项目名称:Camelot-Unchained-Client-Library,代码行数:26,代码来源:EnemyTargetStore.ts

示例6: init

    const store = Reflux.createStore({
      topic: events.clientEventTopics.handlesAnnouncements,
      listenables: actions,
      init() {
        // Initialise the store is basic info.  This is so that React components
        // can use the Store to initialise their state in getDefaultState().
        this.info = {
          message: "",
          type: -1
        };
      },
      start() {
        console.log('in AnnouncementStore:start()');
        const store = this;

        // If this store has already been started, then ingore subsequent start
        // request
        if (this.started) return;
        this.started = true;

        // Listen to the event group for this unit frame
        events.on(this.topic, (announcement: any) => {

          // Update store info
          store.info = {
            message: announcement.message,
            type: announcement.type
          };

          // Trigger changed notification for this store
          store.trigger(store.info);
        });
      },
      stop() {
        // TODO
      }
    });
开发者ID:Fidaman,项目名称:Camelot-Unchained,代码行数:37,代码来源:AnnouncementsStore.ts

示例7:

// Type definitions for reflux 0.3.0
// Project: https://github.com/reflux/refluxjs
// Definitions by: saddieeiddas <https://github.com/saddieeiddas>

/// <reference path="reflux.d.ts" />

import * as Reflux from 'reflux';

console.log(Reflux.version['reflux-core']);
console.log(Reflux.createStore({}));
console.log(Reflux.PublisherMethods.triggerPromise().then());

console.log(Reflux.createActions({
  test1: () => {},
  test2: () => {},
}));

console.log(Reflux.EventEmitter);
console.log(Reflux.utils.EventEmitter);
console.log(Reflux.Promise);

console.log(Reflux.connect('test', 'test').getInitialState());

console.log(Reflux.ListenerMixin.componentWillUnmount());

console.log(Reflux.listenTo('test', () => {}, () => {}).componentWillUnmount());
开发者ID:CUModSquad,项目名称:Typings,代码行数:26,代码来源:reflux.test.ts

示例8: create

/**
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

import * as Reflux from 'reflux';
import events from '../../events/events';
import _UnitFrame from './_UnitFrame';

const CharacterStore = {
  create() {
    const actions = Reflux.createActions(['start', 'stop']);
    const store = Reflux.createStore({
      mixins: [_UnitFrame],
      handles: events.handlesCharacter,
      listenables: actions
    });
    return {
      store: store,
      actions: actions
    };
  }
};

export default CharacterStore;
开发者ID:Fidaman,项目名称:Camelot-Unchained-Client-Library,代码行数:26,代码来源:CharacterStore.ts


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