https://github.com/joelburget/hubble
javascript lenses
https://github.com/joelburget/hubble
Last synced: 7 months ago
JSON representation
javascript lenses
- Host: GitHub
- URL: https://github.com/joelburget/hubble
- Owner: joelburget
- Created: 2014-07-29T17:29:54.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-01-26T19:06:23.000Z (over 10 years ago)
- Last Synced: 2024-11-29T21:44:48.690Z (7 months ago)
- Language: JavaScript
- Size: 207 KB
- Stars: 15
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Hubble
a javascript lens library

## What Does That Mean?
This library makes it easy to inspect and manipulate data structures. In particular lenses excel at efficient immutable update.
That's a mouthful, but I think it's easiest to understand through examples.
```javascript
// data structure to manipulate
var recipe = {
ingredients: [
{
name: "chocolate",
quantity: "1 cup"
}
],
steps: [
"unwrap chocolate",
"eat chocolate"
]
};// get part of the data structure. in this case we're getting the name of the
zero-th element of ingredients.
lens(recipe).get(["ingredients", 0, "name"])
// returns "chocolate"// we can also get a modified version of the data structure
// this doesn't modify the original
var newRecipe = lens(recipe)
.set(["steps", 0], "unwrap chocolate, without eating all of it")
.freeze();
// returns a structure that looks just like `recipe`, but with a different
// first step
```Using immutable-js? There's support for that too.
```javascript
var immutableRecipe = Immutable.fromJS(recipe);// our previous examples still work! get and set values with a simple
// interface. Modifications are batched.
lens(immutableRecipe).get(["ingredients", 0, "name"])var newRecipe = lens(immutableRecipe)
.set(["steps", 0], "unwrap chocolate, without eating all of it")
.freeze();
```## Up and Running in One Easy Step
TODO
## Reference
TODO