Skip to content

Commit 51268e1

Browse files
committed
Merge branch 'tkqubo-react-mixin'
2 parents cc2065a + b2a8346 commit 51268e1

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

react-mixin/react-mixin-tests.tsx

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/// <reference path="react-mixin.d.ts" />
2+
/// <reference path="../react/react.d.ts" />
3+
4+
import reactMixin = require('react-mixin');
5+
import * as React from 'react';
6+
7+
var someMixin: React.Mixin<any, any>;
8+
var someOtherMixin: React.Mixin<any, any>;
9+
10+
class Foo extends React.Component<any, any> {
11+
render(): JSX.Element { return <div />; }
12+
}
13+
14+
reactMixin(Foo.prototype, someMixin);
15+
reactMixin(Foo.prototype, someOtherMixin);
16+
17+
18+
var mixin: React.Mixin<any, any> = {
19+
getDefaultProps: function(): any {
20+
return {b: 2};
21+
}
22+
};
23+
24+
class Foo2 extends React.Component<any, any> {
25+
static defaultProps = {
26+
a: 1
27+
};
28+
render(): JSX.Element {
29+
console.log(this.props); // {a: 1, b: 2}
30+
return null;
31+
}
32+
}
33+
34+
reactMixin.onClass(Foo2, mixin);
35+
36+
@reactMixin.decorate(mixin)
37+
class Foo3 extends React.Component<any, any> {
38+
}
39+
40+
function autobind(methodNames: string[]): React.Mixin<any, any> {
41+
return {
42+
componentWillMount: function(): void {
43+
methodNames.forEach((name) => {
44+
this[name] = this[name].bind(this);
45+
});
46+
}
47+
};
48+
}
49+
50+
@reactMixin.decorate(mixin)
51+
@reactMixin.decorate(autobind(Object.keys(mixin)))
52+
class Foo4 extends React.Component<any, any> {
53+
}
54+
55+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--target es5 --noImplicitAny --experimentalDecorators --jsx react

react-mixin/react-mixin.d.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Type definitions for react-mixin 2.0.2
2+
// Project: https://github.com/brigand/react-mixin
3+
// Definitions by: Qubo <https://github.com/tkqubo>
4+
// Definitions: https://github.com/borisyankov/DefinitelyTyped
5+
6+
/// <reference path="../react/react.d.ts" />
7+
8+
declare module "react-mixin" {
9+
import * as React from 'react';
10+
11+
namespace reactMixin {
12+
export interface ClassDecorator {
13+
<TFunction extends Function>(target: TFunction): TFunction|void;
14+
}
15+
16+
interface ReactMixin {
17+
decorate(mixin: React.Mixin<any, any>): ClassDecorator;
18+
onClass<S>(clazz: any, mixin: React.Mixin<any, any>): React.ComponentClass<S>;
19+
<S>(clazz: any, mixin: React.Mixin<any, any>): React.ComponentClass<S>;
20+
}
21+
}
22+
23+
var reactMixin: reactMixin.ReactMixin;
24+
25+
export = reactMixin;
26+
}
27+

0 commit comments

Comments
 (0)