-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
55 lines (41 loc) · 1.7 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Re-export react-mvx
import ReactMVx from 'react-mvx'
const NestedReact = Object.create( ReactMVx );
export default NestedReact;
export * from 'react-mvx'
// NestedReact backward compatibility layer
import * as ReactDOM from 'react-dom'
import Nested, { View, Record } from 'nestedtypes'
import * as PropTypes from 'prop-types'
import subview from './view-element'
NestedReact.subview = subview;
export { subview }
import use from './component-view'
import createClass from './createClass'
Object.defineProperty( NestedReact, 'createClass', { value : createClass} );
Object.defineProperty( NestedReact, 'PropTypes', { value : PropTypes } );
export { PropTypes, createClass };
let BaseView;
// export hook to override base View class used...
export function useView( View ){
BaseView = use( View );
}
const { onDefine } = NestedReact.Component;
NestedReact.Component.onDefine = function( definitions, BaseClass ){
this.View = BaseView.extend( { reactClass : this } );
return onDefine.call( this, definitions, BaseClass );
}
// Deprecated API for backward compatibility
const RecordProto : any = Record.prototype;
RecordProto.getLink = RecordProto.linkAt;
RecordProto.deepLink = RecordProto.linkPath;
const CollectionProto : any = Record.Collection.prototype;
CollectionProto.hasLink = CollectionProto.linkContains;
useView( View );
// Extend react components to have backbone-style jquery accessors
const BackboneViewProps = {
el : { get : function(){ return ReactDOM.findDOMNode( this ) } },
$el : { get : function(){ return Nested.$( this.el ) } },
$ : { value : function( sel ){ return this.$el.find( sel ) } }
};
Object.defineProperties( NestedReact.Component.prototype, BackboneViewProps );