2
2
import action from '@cocreate/actions' ;
3
3
import observer from '@cocreate/observer' ;
4
4
import uuid from '@cocreate/uuid' ;
5
- import { queryDocumentSelector } from '@cocreate/utils' ;
5
+ import { queryDocumentSelector , getValueFromObject } from '@cocreate/utils' ;
6
6
import '@cocreate/element-prototype' ;
7
7
import './index.css' ;
8
8
// import api from '@cocreate/api';
9
9
10
10
const CoCreateRender = {
11
- // Can be called from utils getValueFromObject
12
- __getValueFromObject : function ( json , path ) {
13
- try {
14
- if ( typeof json == 'undefined' || ! path )
15
- return false ;
16
- if ( path . indexOf ( '.' ) == - 1 && path . includes ( 'collection' ) )
17
- json = this . dataOriginal
18
- if ( / \[ ( [ 0 - 9 ] * ) \] / g. test ( path ) ) {
19
- path = path . replace ( / \[ / g, '.' ) ;
20
- if ( path . endsWith ( ']' ) )
21
- path = path . slice ( 0 , - 1 )
22
- path = path . replace ( / \] ./ g, '.' ) ;
23
- path = path . replace ( / \] / g, '.' ) ;
24
- }
25
- let jsonData = json , subpath = path . split ( '.' ) ;
26
-
27
- for ( let i = 0 ; i < subpath . length ; i ++ ) {
28
- jsonData = jsonData [ subpath [ i ] ] ;
29
- if ( ! jsonData ) return false ;
30
- }
31
- return jsonData ;
32
- } catch ( error ) {
33
- console . log ( "Error in getValueFromObject" , error ) ;
34
- return false ;
35
- }
36
- } ,
37
11
38
12
__getValue : function ( data , attrValue ) {
39
13
let result = / { { \s * ( [ \w \W ] + ) \s * } } / g. exec ( attrValue ) ;
40
14
if ( result ) {
41
- return this . __getValueFromObject ( data , result [ 1 ] . trim ( ) ) ;
15
+ return getValueFromObject ( data , result [ 1 ] . trim ( ) ) ;
42
16
}
43
17
return false ;
44
18
} ,
@@ -141,7 +115,7 @@ const CoCreateRender = {
141
115
template . renderedKeys = new Map ( )
142
116
143
117
if ( isRenderObject && type ) {
144
- let Data = self . __getValueFromObject ( arrayData , type ) ;
118
+ let Data = self . getValueFromObject ( arrayData , type ) ;
145
119
let array = self . isRenderObject ( Data , renderKey )
146
120
for ( let item of array ) {
147
121
if ( ! template . renderedKeys . has ( item [ renderKey ] . key ) ) {
@@ -155,7 +129,7 @@ const CoCreateRender = {
155
129
} else {
156
130
157
131
if ( ! Array . isArray ( arrayData ) )
158
- arrayData = this . __getValueFromObject ( data , type ) ;
132
+ arrayData = getValueFromObject ( data , type ) ;
159
133
160
134
if ( ! arrayData ) {
161
135
let cloneEl = this . cloneEl ( template ) ;
0 commit comments