Magic Variables in RecoilJS

My friend Bobbo (professionally known as Robert Messerle) is writing a very cool Javascript framework, called RecoilJS, to perform content binding & view composition using some techniques borrowed from AngularJS, but with more of a focus on large javascript application development. I tend to be his guinea pig, as I’m willing to use his framework in my primary work environment.

Anyway, while it does some really neat stuff very easily and with little cruft, there’s also not exactly a lot of documentation on it as he still feels there is development work to be done.

So, to do him a huge solid, here are some of the “magic” variables that he exposes in the current scope, which make it possible to do neat things:

  • $scope – this gives you access to the current binding context scope. This would allow you to do things like…set variables: data-init=”$scope.notRecommended=true”
  • $element – a jQuery object containing the  HTML DOM node that is currently being evaluated
  • $parent – the parent binding context. Gives you access to the next level up from inside a child context using data-compose
  • $data – gives you raw access to the current object being evaluated by $scope, but without any extra magical stuff. Useful if you’re trying to data-compose on an array
  • $extras – playing with this isn’t necessarily recommended, but it’s there. Populated with useful data only in data-for interations, the $extras object is populated with the following properties - itemName – the name of the object in the containing object/array
  • $item – data item being bound
  • [itemName] – again the data item being bound
  • [itemName].$index – the index number of the item in the display list gets stuffed into the item itself.