11
2- dop . core . createComputed = function ( object , property , f , shallWeSet , oldValue ) {
3-
4- var computed_id = dop . data . computed_inc ++ ,
5- data_path = dop . data . path ,
6- derived_paths ,
7- derived_pathsids = [ ] ,
8- derived_path ,
9- derived_pathid ,
10- computed_path ,
11- computed_pathid ,
12- value ,
13- index = 0 ,
14- total ,
15- index2 ,
16- total2 ;
17-
18-
19- // Running function and saving paths from getters
20- dop . data . gets_collecting = true ;
21- value = f . call ( object , oldValue ) ;
22- dop . data . gets_collecting = false ;
23- derived_paths = dop . data . gets_paths ;
24- dop . data . gets_paths = [ ] ;
25-
26-
27- // Generating and storing paths ids
28- for ( total = derived_paths . length ; index < total ; ++ index ) {
29- derived_path = derived_paths [ index ] ;
30- derived_pathid = '' ;
31- for ( index2 = 0 , total2 = derived_path . length ; index2 < total2 ; ++ index2 ) {
32- derived_pathid += dop . core . pathSeparator ( derived_path [ index2 ] ) ;
33- if ( index2 > 0 ) {
34- if ( data_path [ derived_pathid ] === undefined )
35- data_path [ derived_pathid ] = { } ;
36-
37- if ( data_path [ derived_pathid ] . derivations === undefined )
38- data_path [ derived_pathid ] . derivations = [ ] ;
39-
40- if ( data_path [ derived_pathid ] . derivations . indexOf ( computed_id ) < 0 ) {
41- data_path [ derived_pathid ] . derivations . push ( computed_id ) ;
42- derived_pathsids . push ( derived_pathid ) ;
43- }
44- }
45- }
46- }
2+ dop . core . createComputed = function ( object , prop , f , shallWeSet , oldValue ) {
3+ var data_path = dop . data . path ,
4+ computed_id = dop . data . computed_inc ++ ,
5+ computed = {
6+ object_root : dop . getObjectRoot ( object ) ,
7+ prop : prop ,
8+ function : f ,
9+ derivations : [ ]
10+ } ,
11+ path = dop . getObjectPath ( object , false ) ;
4712
48- computed_path = dop . getObjectPath ( object , false ) ;
49- computed_pathid = dop . core . getPathId ( computed_path . concat ( property ) ) ;
13+ computed . path = path . slice ( 1 ) ;
14+ computed . pathid = dop . core . getPathId ( path . concat ( prop ) ) ;
5015
51- // Storing computed in dop.data
52- if ( data_path [ computed_pathid ] === undefined )
53- data_path [ computed_pathid ] = { } ;
16+ if ( data_path [ computed . pathid ] === undefined )
17+ data_path [ computed . pathid ] = { } ;
5418
55- if ( data_path [ computed_pathid ] . computeds === undefined )
56- data_path [ computed_pathid ] . computeds = [ ] ;
57-
58- data_path [ computed_pathid ] . computeds . push ( computed_id ) ;
19+ if ( data_path [ computed . pathid ] . computeds === undefined )
20+ data_path [ computed . pathid ] . computeds = [ ] ;
5921
60- dop . data . computed [ computed_id ] = {
61- object_root : dop . getObjectRoot ( object ) ,
62- path : computed_path . slice ( 1 ) ,
63- prop : property ,
64- function : f ,
65- derivations : derived_pathsids
66- } ;
22+ dop . data . computed [ computed_id ] = computed ;
23+ value = dop . core . updateComputed ( computed_id , computed , object , oldValue ) ;
6724
6825 // Setting value
6926 if ( shallWeSet )
70- dop . core . set ( object , property , value ) ;
27+ dop . core . set ( object , prop , value ) ;
7128
7229 return value ;
7330} ;
0 commit comments