mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-01 15:50:13 +00:00
Merge branch 'tkqubo-react-mixin'
This commit is contained in:
55
react-mixin/react-mixin-tests.tsx
Normal file
55
react-mixin/react-mixin-tests.tsx
Normal 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> {
|
||||
}
|
||||
|
||||
|
||||
1
react-mixin/react-mixin-tests.tsx.tscparams
Normal file
1
react-mixin/react-mixin-tests.tsx.tscparams
Normal file
@@ -0,0 +1 @@
|
||||
--target es5 --noImplicitAny --experimentalDecorators --jsx react
|
||||
27
react-mixin/react-mixin.d.ts
vendored
Normal file
27
react-mixin/react-mixin.d.ts
vendored
Normal 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user