當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。