File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -188,7 +188,6 @@ let rule = new Rule({
188188 fact: ' product-price' ,
189189 params: {
190190 productId: ' widget' ,
191- // Complex accessor are supported, e.g. '.profile.addresses[0].city'
192191 path: ' .price'
193192 },
194193 operator: ' greaterThan' ,
@@ -198,7 +197,34 @@ let rule = new Rule({
198197 }
199198})
200199```
201- See the [ fact-dependency] ( ../examples/04-fact-dependency.js ) example
200+
201+ To access nested properties, use dot/bracket-notation:
202+ ``` js
203+ /*
204+ {
205+ profile: {
206+ addresses: [{ city: 'Denver' }]
207+ }
208+ }
209+ */
210+
211+ path: ' .profile.addresses[0].city' // "Denver"
212+ ```
213+
214+ To access properties with a '.', pass an array of properties
215+ ``` js
216+ /*
217+ {
218+ property: {
219+ 'dot.property': 'hello-world'
220+ }
221+ }
222+ */
223+ path: [' property' , ' dot.property' ] // "hello-world"
224+ ```
225+ Full documentation for ` path ` can be found in the [ selectn] ( https://github.com/wilmoore/selectn.js ) library
226+
227+ For an example, see [ fact-dependency] ( ../examples/04-fact-dependency.js )
202228
203229### Comparing facts
204230
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ async function eligibilityData (params, engine) {
2323 name : 'Colorado'
2424 } ,
2525 zip : '80403' ,
26+ 'dot.property' : 'dot-property-value' ,
2627 occupantHistory : [
2728 { name : 'Joe' , year : 2011 } ,
2829 { name : 'Jane' , year : 2013 }
@@ -171,6 +172,16 @@ describe('Engine: fact evaluation', () => {
171172 expect ( successSpy ) . to . have . been . calledWith ( event )
172173 } )
173174
175+ it ( 'correctly interprets "path" when target object properties have dots' , async ( ) => {
176+ let complexCondition = conditions ( )
177+ complexCondition . any [ 0 ] . path = [ 'address' , 'dot.property' ]
178+ complexCondition . any [ 0 ] . value = 'dot-property-value'
179+ complexCondition . any [ 0 ] . operator = 'equal'
180+ setup ( complexCondition )
181+ await engine . run ( )
182+ expect ( successSpy ) . to . have . been . calledWith ( event )
183+ } )
184+
174185 it ( 'correctly interprets "path" with runtime fact objects' , async ( ) => {
175186 let fact = { x : { y : 1 } , a : 2 }
176187 let conditions = {
You can’t perform that action at this time.
0 commit comments