https://github.com/default-writer/lazyeval
Minimalist Lazy Evaluation JavaSctipt famework
https://github.com/default-writer/lazyeval
Last synced: about 1 year ago
JSON representation
Minimalist Lazy Evaluation JavaSctipt famework
- Host: GitHub
- URL: https://github.com/default-writer/lazyeval
- Owner: default-writer
- License: mit
- Created: 2018-08-01T13:48:31.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-07-21T07:30:51.000Z (almost 4 years ago)
- Last Synced: 2025-04-05T07:15:25.797Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 16.6 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lazyeval
Minimalist Lazy Evaluation JavaSctipt famework
```js
let lazy = (eval) => ((data) => new Proxy(data, {
set(obj, key, val) {
obj[key] = val;
eval(obj);
}
}))({});
```
https://github.com/hack2root/lazyeval
[](https://packagephobia.now.sh/result?p=@root_admin/lazyeval@1.0.1)
## Example
- func is a proxy for an empty objct {}
- func calls evaluation function every time you write to existing, new or user defined properties
- func updates internal object and passes it as an argument for every call to evaluation function
- f is a parameter pointing to the internal representation of the external object {}
- c is not evaluated until all requirements for evaluation is met for evaluation function
```js
describe('let func = lazy((f) => { if (f.a && f.b) { c = f.a + f.b } })', function () {
it('should add two numbers', function () {
// 1. ARRANGE
let a = 1;
let b = 2;
let c;
// 2. ACT
let func = lazy((f) => {
if (f.a && f.b) {
c = f.a + f.b
}
});
func.a = a;
func.b = b;
// 3. ASSERT
expect(c).to.be.equal(3);
});
});
```