bolt icon indicating copy to clipboard operation
bolt copied to clipboard

`this` and `prior(this)` are ignored in functions

Open bijoutrouvaille opened this issue 9 years ago • 1 comments

An example test.bolt,

path /unchangeable1 {
  write() { isTheSame() }
}

path /unchangeable2 {
  write() { prior(this)==this }
}

isTheSame() { prior(this)==this }

renders to the following,

{
  "rules": {
    "unchangeable1": {
      ".write": "this == this"
    },
    "unchangeable2": {
      ".write": "data.val() == newData.val()"
    }
  }
}

Am I missing the idea or should unchangeable1 be rendered the same as unchangeable2?

bijoutrouvaille avatar Sep 20 '16 22:09 bijoutrouvaille

This should probably return an error at compile time. I think the issue is that the value of 'this' is defined inside a validation or write rule, but is not bound in the function.

To get around this, you can pass this as a parameter to your function instead.

mckoss avatar Nov 15 '16 17:11 mckoss