DefinitelyTyped/types/fluxible-addons-react/fluxible-addons-react-tests.ts
Max 3d4028cde1 add missing types and functions to fluxible (#28729)
* add types for package 'fluxible'

* add fluxible router types

* fix tests

* fixed annotation

* add missing types

* fix tsconfig.json

* fix for lint

* fix lint

* fix name of a package

* add missing description

* delete bad copypaste

* add test file

* add tests

* fix getStore type check
2018-10-09 10:53:16 -07:00

53 lines
1.2 KiB
TypeScript

import { DispatcherInterface } from 'dispatchr';
import { connectToStores, provideContext } from 'fluxible-addons-react';
import { Fluxible, ComponentContext } from 'fluxible';
import BaseStore = require('fluxible/addons/BaseStore');
import * as React from 'react';
interface HomeProps {
stringValue: string;
}
class Home extends React.Component<HomeProps, any> {
constructor(props: HomeProps) {
super(props);
}
}
class ExtendedStore extends BaseStore {
constructor(public dispatcher: DispatcherInterface) {
super(dispatcher);
this.data = "";
}
static storeName = 'ExtendedStore';
static handlers = {
ACTION_NAME: 'actionHandler'
};
private data: string;
actionHandler() {
this.emitChange();
}
setData(data: string): void {
this.data = data;
}
getData(): string {
return this.data;
}
}
// connecting Home react component to ExtendedStore
const ConnectedComponent = connectToStores(Home, [ExtendedStore], (context: ComponentContext, props: HomeProps) => {
return {
stringValue: context.getStore(ExtendedStore).getData(),
};
});
const ConnectedComponentWithContext = provideContext(ConnectedComponent);