@@ -72,7 +72,7 @@ public FallbackPatchListener Listen(Action<PatchObject> callback)
72
72
return listener ;
73
73
}
74
74
75
- public PatchListener Listen ( string segments , Action < DataChange > callback ) {
75
+ public PatchListener Listen ( string segments , Action < DataChange > callback , bool immediate = false ) {
76
76
var rawRules = segments . Split ( '/' ) ;
77
77
var regexpRules = this . ParseRegexRules ( rawRules ) ;
78
78
@@ -84,6 +84,12 @@ public PatchListener Listen(string segments, Action<DataChange> callback) {
84
84
85
85
this . listeners . Add ( listener ) ;
86
86
87
+ if ( immediate ) {
88
+ List < PatchListener > onlyListener = new List < PatchListener > ( ) ;
89
+ onlyListener . Add ( listener ) ;
90
+ this . CheckPatches ( Compare . GetPatchList ( new IndexedDictionary < string , object > ( ) , this . state ) , onlyListener ) ;
91
+ }
92
+
87
93
return listener ;
88
94
}
89
95
@@ -128,23 +134,29 @@ protected Regex[] ParseRegexRules (string[] rules)
128
134
return regexpRules ;
129
135
}
130
136
131
- private void CheckPatches ( PatchObject [ ] patches )
137
+ private void CheckPatches ( PatchObject [ ] patches , List < PatchListener > _listeners = null )
132
138
{
139
+ if ( _listeners == null )
140
+ {
141
+ _listeners = this . listeners ;
142
+ }
133
143
134
144
for ( var i = patches . Length - 1 ; i >= 0 ; i -- )
135
145
{
136
146
var matched = false ;
137
147
138
- for ( var j = 0 ; j < this . listeners . Count ; j ++ )
148
+ for ( var j = 0 ; j < _listeners . Count ; j ++ )
139
149
{
140
- var listener = this . listeners [ j ] ;
150
+ var listener = _listeners [ j ] ;
141
151
var pathVariables = this . GetPathVariables ( patches [ i ] , listener ) ;
142
152
if ( pathVariables != null )
143
153
{
144
- var dataChange = new DataChange ( ) ;
145
- dataChange . path = pathVariables ;
146
- dataChange . operation = patches [ i ] . operation ;
147
- dataChange . value = patches [ i ] . value ;
154
+ DataChange dataChange = new DataChange
155
+ {
156
+ path = pathVariables ,
157
+ operation = patches [ i ] . operation ,
158
+ value = patches [ i ] . value
159
+ } ;
148
160
149
161
listener . callback . Invoke ( dataChange ) ;
150
162
matched = true ;
0 commit comments