20
20
21
21
import React , { createElement } from 'react' ;
22
22
import PropTypes from 'prop-types' ;
23
- import { Deck , View , log } from '@deck.gl/core' ;
23
+ import { Deck , experimental } from '@deck.gl/core' ;
24
+ const { memoize} = experimental ;
25
+
24
26
import extractJSXLayers from './utils/extract-jsx-layers' ;
25
- import { inheritsFrom } from './utils/inherits-from' ;
26
- import evaluateChildren from './utils/evaluate-children' ;
27
+ import positionChildrenUnderViews from './utils/position-children-under-views' ;
27
28
import autobind from './utils/autobind' ;
28
29
29
30
const propTypes = Deck . getPropTypes ( PropTypes ) ;
@@ -35,12 +36,15 @@ export default class DeckGL extends React.PureComponent {
35
36
super ( props ) ;
36
37
37
38
this . viewports = null ;
38
- this . children = [ ] ;
39
39
40
40
// The redraw flag of deck
41
41
this . _needsRedraw = null ;
42
42
43
43
autobind ( this ) ;
44
+
45
+ // Memoized functions
46
+ this . _extractJSXLayers = memoize ( extractJSXLayers ) ;
47
+ this . _positionChildrenUnderViews = memoize ( positionChildrenUnderViews ) ;
44
48
}
45
49
46
50
componentDidMount ( ) {
@@ -101,14 +105,6 @@ export default class DeckGL extends React.PureComponent {
101
105
return this . deck . pickObjects ( { x, y, width, height, layerIds} ) ;
102
106
}
103
107
104
- queryObject ( opts ) {
105
- log . removed ( 'queryObject' , 'pickObject' ) ( ) ;
106
- }
107
-
108
- queryVisibleObjects ( opts ) {
109
- log . removed ( 'queryVisibleObjects' , 'pickObjects' ) ( ) ;
110
- }
111
-
112
108
// Callbacks
113
109
_redrawDeck ( ) {
114
110
if ( this . _needsRedraw ) {
@@ -137,6 +133,14 @@ export default class DeckGL extends React.PureComponent {
137
133
138
134
// Private Helpers
139
135
136
+ _parseJSX ( ) {
137
+ return this . _extractJSXLayers ( {
138
+ layers : this . props . layers ,
139
+ views : this . props . views ,
140
+ children : this . props . children
141
+ } ) ;
142
+ }
143
+
140
144
// 1. Extract any JSX layers from the react children
141
145
// 2. Handle any backwards compatiblity props for React layer
142
146
// Needs to be called both from initial mount, and when props have changed
@@ -146,77 +150,27 @@ export default class DeckGL extends React.PureComponent {
146
150
}
147
151
148
152
// extract any deck.gl layers masquerading as react elements from props.children
149
- const { layers, views, children} = extractJSXLayers ( this . props ) ;
150
-
153
+ const { layers, views} = this . _parseJSX ( ) ;
151
154
const deckProps = Object . assign ( { } , this . props , {
152
155
layers,
153
156
views
154
157
} ) ;
155
158
156
159
this . deck . setProps ( deckProps ) ;
157
-
158
- this . children = children ;
159
160
}
160
161
161
- // Iterate over views and reposition children associated with views
162
- // TODO - Can we supply a similar function for the non-React case?
163
- _positionChildrenUnderViews ( children ) {
162
+ render ( ) {
163
+ // Save the viewports used for this render
164
164
const { viewManager} = this . deck || { } ;
165
+ this . viewports = viewManager && viewManager . getViewports ( ) ;
165
166
166
- if ( ! viewManager || ! viewManager . views . length ) {
167
- return [ ] ;
168
- }
169
-
170
- const defaultViewId = viewManager . views [ 0 ] . id ;
171
- // Save the viewports used for the last render
172
- this . viewports = viewManager . getViewports ( ) ;
173
-
174
- return children . map ( ( child , i ) => {
175
- if ( child . props . viewportId ) {
176
- log . removed ( 'viewportId' , '<View>' ) ( ) ;
177
- }
178
- if ( child . props . viewId ) {
179
- log . removed ( 'viewId' , '<View>' ) ( ) ;
180
- }
181
-
182
- // Unless child is a View, position / render as part of the default view
183
- let viewId = defaultViewId ;
184
- let viewChildren = child ;
185
- if ( inheritsFrom ( child . type , View ) ) {
186
- viewId = child . props . id || defaultViewId ;
187
- viewChildren = child . props . children ;
188
- }
189
-
190
- const viewport = viewManager . getViewport ( viewId ) ;
191
- const viewState = viewManager . getViewState ( viewId ) ;
192
-
193
- // Drop (auto-hide) elements with viewId that are not matched by any current view
194
- if ( ! viewport ) {
195
- return null ;
196
- }
197
-
198
- // Resolve potentially relative dimensions using the deck.gl container size
199
- const { x, y, width, height} = viewport ;
200
-
201
- viewChildren = evaluateChildren ( viewChildren , {
202
- x,
203
- y,
204
- width,
205
- height,
206
- viewport,
207
- viewState
208
- } ) ;
209
-
210
- const style = { position : 'absolute' , left : x , top : y , width, height} ;
211
- const key = `view-child-${ viewId } -${ i } ` ;
212
- return createElement ( 'div' , { key, id : key , style} , viewChildren ) ;
213
- } ) ;
214
- }
215
-
216
- render ( ) {
217
167
// Render the background elements (typically react-map-gl instances)
218
168
// using the view descriptors
219
- const children = this . _positionChildrenUnderViews ( this . children ) ;
169
+ const children = this . _positionChildrenUnderViews ( {
170
+ children : this . _parseJSX ( ) . children ,
171
+ viewports : this . viewports ,
172
+ deck : this . deck
173
+ } ) ;
220
174
221
175
// TODO - this styling is enforced for correct positioning with children
222
176
// It can override the styling set by `Deck`, this should be consolidated.
0 commit comments