Introduction
Yzal (Lazy written backwards) is a function that allows you to implement complete computation dependency trees with little effort. It acts a bit like a "lazy" spreadsheet in that if a value C depends on A and B, C will only get calculated on first call or if B or C have changed.
Installation
npm i --save yzal
Example
let lazy = let foo = a:1 b:2 bar = a:5 b:3 let a = b = c = // Will compute a,b then cconsole // Will used cached value for cconsole // Will re-compute a then cfooa = 3console
Strict Mode
In normal mode, dependencies are compared using deep equality. This can be wastefull and expensive if the source data is very large. Ideally, you are using immutable source, which can be compared using === instead.
Example
let someHugeArray = ... let c = // Will compute cconsole // Will used cached value for c because// reference to someHugeArray has not changedsomeHugeArray0 = 0someHugeArray123456 = 0console // Will re-compute c because the reference has changedsomeHugeArray = ...someHugeArrayconsole # License The MIT 2015 Eric Methot Permission is hereby granted free of charge to any person obtaining a copyof this software and associated documentation to dealin the Software without restriction including without limitation the rightsto use copy modify merge publish distribute sublicense and/or sellcopies of the Software and to permit persons to whom the Software isfurnished to do so subject to the following conditions: The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND EXPRESS ORIMPLIED INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITYFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM DAMAGES OR OTHERLIABILITY WHETHER IN AN ACTION OF CONTRACT TORT OR OTHERWISE ARISING FROMOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS INTHE SOFTWARE