Merge branch 'tkqubo-react-mixin'

This commit is contained in:
vvakame
2015-09-23 06:10:48 +09:00
3 changed files with 83 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
/// <reference path="react-mixin.d.ts" />
/// <reference path="../react/react.d.ts" />
import reactMixin = require('react-mixin');
import * as React from 'react';
var someMixin: React.Mixin<any, any>;
var someOtherMixin: React.Mixin<any, any>;
class Foo extends React.Component<any, any> {
render(): JSX.Element { return <div />; }
}
reactMixin(Foo.prototype, someMixin);
reactMixin(Foo.prototype, someOtherMixin);
var mixin: React.Mixin<any, any> = {
getDefaultProps: function(): any {
return {b: 2};
}
};
class Foo2 extends React.Component<any, any> {
static defaultProps = {
a: 1
};
render(): JSX.Element {
console.log(this.props); // {a: 1, b: 2}
return null;
}
}
reactMixin.onClass(Foo2, mixin);
@reactMixin.decorate(mixin)
class Foo3 extends React.Component<any, any> {
}
function autobind(methodNames: string[]): React.Mixin<any, any> {
return {
componentWillMount: function(): void {
methodNames.forEach((name) => {
this[name] = this[name].bind(this);
});
}
};
}
@reactMixin.decorate(mixin)
@reactMixin.decorate(autobind(Object.keys(mixin)))
class Foo4 extends React.Component<any, any> {
}

View File

@@ -0,0 +1 @@
--target es5 --noImplicitAny --experimentalDecorators --jsx react

27
react-mixin/react-mixin.d.ts vendored Normal file
View File

@@ -0,0 +1,27 @@
// Type definitions for react-mixin 2.0.2
// Project: https://github.com/brigand/react-mixin
// Definitions by: Qubo <https://github.com/tkqubo>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../react/react.d.ts" />
declare module "react-mixin" {
import * as React from 'react';
namespace reactMixin {
export interface ClassDecorator {
<TFunction extends Function>(target: TFunction): TFunction|void;
}
interface ReactMixin {
decorate(mixin: React.Mixin<any, any>): ClassDecorator;
onClass<S>(clazz: any, mixin: React.Mixin<any, any>): React.ComponentClass<S>;
<S>(clazz: any, mixin: React.Mixin<any, any>): React.ComponentClass<S>;
}
}
var reactMixin: reactMixin.ReactMixin;
export = reactMixin;
}