Skip to content

Commit

Permalink
renamed observ-hash to observ-struct
Browse files Browse the repository at this point in the history
  • Loading branch information
Raynos committed Jun 2, 2014
1 parent c26ed82 commit f5670d4
Show file tree
Hide file tree
Showing 23 changed files with 84 additions and 83 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ The following examples demonstrate how you can mix & match

- mercury leverages [`virtual-dom`][virtual-dom] which uses
an immutable vdom structure
- mercury comes with [`observ-hash`][observ-hash] which uses
- mercury comes with [`observ-struct`][observ-struct] which uses
immutable data for your state atom
- mercury is truly modular, you can trivially swap out
subsets of it for other modules
Expand Down Expand Up @@ -114,7 +114,7 @@ If `mercury` is not ideal for your needs, you should check out
Alternatively if the default set of modules in `mercury` doesn't
work for you, you can just require other modules. It's possible
to for example, swap out [`vtree`][vtree] with
[`react`][react] or swap out [`observ-hash`][observ-hash]
[`react`][react] or swap out [`observ-struct`][observ-struct]
with [`backbone`][backbone]

### Input, State, Render and Output
Expand Down Expand Up @@ -219,7 +219,7 @@ It should be noted that [`vdom-thunk`][vdom-thunk] assumes
arguments are immutable and thus does an O(1) `===` check
to see whether the arguments has changed. This will only
work if your state is immutable. Thankfully,
[`observ-hash`][observ-hash] is immutable
[`observ-struct`][observ-struct] is immutable

#### [`main-loop`][main-loop]

Expand Down Expand Up @@ -265,17 +265,17 @@ Generally applications built with mercury will have a single
[`observ`][observ] is basically an implementation of the
`Signal` type that is normally used in FRP.

#### [`observ-hash`][observ-hash]
#### [`observ-struct`][observ-struct]

[`observ-hash`][observ-hash] is an observable that contains an
[`observ-struct`][observ-struct] is an observable that contains an
object with a fixed number of keys. Generally the key-value
pairs in [`observ-hash`][observ-hash] are themself
pairs in [`observ-struct`][observ-struct] are themself
observables. You can change the value of any key in an
[`observ-hash`][observ-hash] and the top level object
[`observ-struct`][observ-struct] and the top level object
will also change to be a new object with that key changed.

[`observ-hash`][observ-hash] uses shallow extension to ensure
that every time the hash changes you get a fresh immutable
[`observ-struct`][observ-struct] uses shallow extension to ensure
that every time the struct changes you get a fresh immutable
object.

#### [`observ-array`][observ-array]
Expand All @@ -292,9 +292,9 @@ Generally applications built with mercury will have a single

[`observ-array`][observ-array] has the benefit of being able
to add or remove items from the array, where as
[`observ-hash`][observ-hash] has a fixed number
[`observ-struct`][observ-struct] has a fixed number
of keys and you cannot add more keys to an
[`observ-hash`][observ-hash]
[`observ-struct`][observ-struct]

### Input modules (The controller layer)

Expand Down Expand Up @@ -434,7 +434,7 @@ A lot of the philosophy and design of `mercury` is inspired by
[vdom-thunk]: https://github.com/Raynos/vdom-thunk
[observ]: https://github.com/Raynos/observ
[observ-computed]: https://github.com/Raynos/observ/blob/master/computed.js
[observ-hash]: https://github.com/Raynos/observ-hash
[observ-struct]: https://github.com/Raynos/observ-struct
[observ-array]: https://github.com/Raynos/observ-array
[geval]: https://github.com/Raynos/geval
[dom-delegator]: https://github.com/Raynos/dom-delegator
Expand Down
2 changes: 1 addition & 1 deletion bin/copy-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var projects = [
'Raynos/dom-delegator',
'Raynos/value-event',
'Raynos/observ-array',
'Raynos/observ-hash',
'Raynos/observ-struct',
'Raynos/observ',
'Matt-Esch/virtual-dom',
'Matt-Esch/vtree',
Expand Down
4 changes: 2 additions & 2 deletions concepts/frame-list/frame-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ function createFrameList(parentState) {
// I shouldn't have to mutate global state with a new key for my purpose
// The internal state is still readable. This is still ref transparent
// and this is still immutable.
var thumbnails = mercury.hash(map(parentState.frames, function (frame) {
var thumbnails = mercury.struct(map(parentState.frames, function (frame) {
return thumbnailify(frame)
}))

var state = mercury.hash({
var state = mercury.struct({
thumbnails: thumbnails,
lastSelect: mercury.value(null)
})
Expand Down
4 changes: 2 additions & 2 deletions concepts/frame-list/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var FrameData = require("./data/frames")
// Load the data
var initialFrameData = FrameData.load()

var frames = mercury.hash(initialFrameData)
var frames = mercury.struct(initialFrameData)
var currentFrame = mercury.value(null)
// Create the frameList component using the frames data
// `frameList` is { state: state, events: events }
Expand All @@ -16,7 +16,7 @@ var frameList = FrameList(frames)
// `frameEditor` is { state: state, events: events }
var frameEditor = FrameEditor(currentFrame)

var state = mercury.hash({
var state = mercury.struct({
frames: frames,
currentFrame: currentFrame,
editor: frameEditor.state,
Expand Down
42 changes: 21 additions & 21 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,22 @@ We have the hook fire immediately by default because sometimes
Firing the hook when the element is in the DOM makes it
impossible to fire it when it's not in the DOM.

## How does `mercury.hash()` unwrapping work
## How does `mercury.struct()` unwrapping work

`mercury.hash()` takes an object whose values are either plain
`mercury.struct()` takes an object whose values are either plain
values or observables.

It then returns both an observable that contains an object
whose values are all plain values (if it sees any observables
it just gets the current value of the observables).

The observable it returns also has the same key value properties
as you passed into `mercury.hash({ ... })`
as you passed into `mercury.struct({ ... })`

Example:

```js
var obj = mercury.hash({
var obj = mercury.struct({
key: 42,
key2: mercury.value(50)
})
Expand All @@ -188,7 +188,7 @@ assert.equal(obj.key2(), 50)
assert.deepEqual(obj(), { key: 42, key2: 50 })
```

When any of the properties passed into `mercury.hash({ ... })`
When any of the properties passed into `mercury.struct({ ... })`
change then the value of the returned observable changes.
Specifically the value of the observable is updated by updating
the changed key to the new plain value
Expand All @@ -205,16 +205,16 @@ obj.key2.set(70)
```

Note that this will work recursively. If you set a value to
another `observ-hash` then when you change a nested property
on the nested `observ-hash` the hash updates which causes an
update to the parent hash.
another `observ-struct` then when you change a nested property
on the nested `observ-struct` the struct updates which causes an
update to the parent struct.

And since `observ-hash` always contains a plain value, the
parent `observ-hash` will also contain a nested plain value
And since `observ-struct` always contains a plain value, the
parent `observ-struct` will also contain a nested plain value

```js
var obj2 = mercury.hash({
foo: mercury.hash({
var obj2 = mercury.struct({
foo: mercury.struct({
bar: mercury.value(10)
})
})
Expand Down Expand Up @@ -270,12 +270,12 @@ Let's say you have a calendar of events where each day can have
Let's take a look at what the state might look like for it

```js
var state = mercury.hash({
calendar: mercury.hash({
var state = mercury.struct({
calendar: mercury.struct({
days: mercury.array([
mercury.hash({
mercury.struct({
events: mercury.array([
mercury.hash({
mercury.struct({
name: 'event name',
isOpen: mercury.value(false),
description: 'event description'
Expand Down Expand Up @@ -338,7 +338,7 @@ What we want to do is get rid of the
access `state.isOpen()` in the event handler, this is a lot
cleaner.

The best way to do this is to move the events hash from the top
The best way to do this is to move the events object from the top
level down to a lower level, basically embed it locally to
the event so that we can make an assumption about the indices.

Expand All @@ -349,7 +349,7 @@ The best way to do this is to use a "mercury component" for the
function EventComponent() {
var events = mercury.input(['toggle']);

var state = mercury.hash({
var state = mercury.struct({
name: 'event name',
isOpen: mercury.value(false),
description: 'event description',
Expand Down Expand Up @@ -387,10 +387,10 @@ We'll need to update our top level state and top level render


```js
var state = mercury.hash({
calendar: mercury.hash({
var state = mercury.struct({
calendar: mercury.struct({
days: mercury.array([
mercury.hash({
mercury.struct({
events: mercury.array([
EventComponent(...).state
])
Expand Down
8 changes: 4 additions & 4 deletions docs/observ-array.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Auto generated from observ-array at version: 1.1.0.
Auto generated from observ-array at version: 1.1.1.

# observ-array

Expand All @@ -23,19 +23,19 @@ An `ObservArray` is an observable version of an array, every

```js
var ObservArray = require("observ-array")
var ObservHash = require("observ-hash")
var ObservStruct = require("observ-struct")
var Observ = require("observ")
var uuid = require("uuid")

function createTodo(title) {
return ObservHash({
return ObservStruct({
id: uuid(),
title: Observ(title || ""),
completed: Observ(false)
})
}

var state = ObservHash({
var state = ObservStruct({
todos: ObservArray([
createTodo("some todo"),
createTodo("some other todo")
Expand Down
40 changes: 20 additions & 20 deletions docs/observ-hash.md → docs/observ-struct.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Auto generated from observ-hash at version: 2.0.0.
Auto generated from observ-struct at version: 3.1.0.

# observ-hash
# observ-struct

<!--
[![build status][1]][2]
Expand All @@ -23,12 +23,12 @@ Nested keys will still be the same value if they were not changed
in that particular `.set()` call.

```js
var ObservHash = require("observ-hash")
var ObservStruct = require("observ-struct")
var Observ = require("observ")
var assert = require("assert")

var state = ObservHash({
fruits: ObservHash({
var state = ObservStruct({
fruits: ObservStruct({
apples: Observ(3),
oranges: Observ(5)
}),
Expand All @@ -55,9 +55,9 @@ state.fruits.apples.set(4)

## Docs

### `var obj = ObservHash(opts)`
### `var obj = ObservStruct(opts)`

`ObservHash()` takes an object literal of string keys to either
`ObservStruct()` takes an object literal of string keys to either
normal values or observable values.

It returns an `Observ` instance `obj`. The value of `obj` is
Expand All @@ -71,23 +71,23 @@ Whenever one of the observables on a `key` changes the `obj` will

## Installation

`npm install observ-hash`
`npm install observ-struct`

## Contributors

- Raynos

## MIT Licenced

[1]: https://secure.travis-ci.org/Raynos/observ-hash.png
[2]: https://travis-ci.org/Raynos/observ-hash
[3]: https://badge.fury.io/js/observ-hash.png
[4]: https://badge.fury.io/js/observ-hash
[5]: https://coveralls.io/repos/Raynos/observ-hash/badge.png
[6]: https://coveralls.io/r/Raynos/observ-hash
[7]: https://gemnasium.com/Raynos/observ-hash.png
[8]: https://gemnasium.com/Raynos/observ-hash
[9]: https://david-dm.org/Raynos/observ-hash.png
[10]: https://david-dm.org/Raynos/observ-hash
[11]: https://ci.testling.com/Raynos/observ-hash.png
[12]: https://ci.testling.com/Raynos/observ-hash
[1]: https://secure.travis-ci.org/Raynos/observ-struct.png
[2]: https://travis-ci.org/Raynos/observ-struct
[3]: https://badge.fury.io/js/observ-struct.png
[4]: https://badge.fury.io/js/observ-struct
[5]: https://coveralls.io/repos/Raynos/observ-struct/badge.png
[6]: https://coveralls.io/r/Raynos/observ-struct
[7]: https://gemnasium.com/Raynos/observ-struct.png
[8]: https://gemnasium.com/Raynos/observ-struct
[9]: https://david-dm.org/Raynos/observ-struct.png
[10]: https://david-dm.org/Raynos/observ-struct
[11]: https://ci.testling.com/Raynos/observ-struct.png
[12]: https://ci.testling.com/Raynos/observ-struct
4 changes: 2 additions & 2 deletions docs/vdom-thunk.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Auto generated from vdom-thunk at version: 2.0.0.
Auto generated from vdom-thunk at version: 2.0.1.

# vdom-thunk

Expand All @@ -20,7 +20,7 @@ Use partial when you want to avoid re-rendering subtrees.

`partial` will only re-evaluate the subtree if the arguments
you pass to it change. This means you should use an immutable
data structure (like `observ-hash`)
data structure (like `observ-struct`)

```js
var partial = require("vdom-thunk")
Expand Down
2 changes: 1 addition & 1 deletion docs/virtual-hyperscript.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Auto generated from virtual-hyperscript at version: 2.4.0.
Auto generated from virtual-hyperscript at version: 3.0.0.

# virtual-hyperscript

Expand Down
2 changes: 1 addition & 1 deletion examples/bmi-counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var mercury = require("../index.js")
var h = mercury.h

var events = mercury.input(["height", "weight", "bmi"])
var bmiData = mercury.hash({
var bmiData = mercury.struct({
height: mercury.value(180),
weight: mercury.value(80),
bmi: mercury.value(calcBmi(180, 80))
Expand Down
2 changes: 1 addition & 1 deletion examples/field-reset.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var h = mercury.h

var events = mercury.input(["reset"])

var state = mercury.hash({
var state = mercury.struct({
isReset: mercury.value(false),
events: events
})
Expand Down
2 changes: 1 addition & 1 deletion examples/geometry/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var shapes = require('./shapes.js')
var dragEvent = require('./drag-handler.js')

var events = mercury.input(['movePoint'])
var state = mercury.hash({
var state = mercury.struct({
p1: mercury.value([100, 100]),
p2: mercury.value([200, 200]),
p3: mercury.value([100, 200]),
Expand Down
2 changes: 1 addition & 1 deletion examples/markdown/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ app.render = appRender
module.exports = app

function app() {
var state = mercury.hash({
var state = mercury.struct({
inlineEditor: inlineMdEditor({
placeholder: 'Enter some markdown...'
}),
Expand Down
2 changes: 1 addition & 1 deletion examples/markdown/component/inlineMdEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function inlineMdEditor(options) {
shouldFocus: focusEditor
})
var renderer = mdRender({ value: options.value })
var state = mercury.hash({
var state = mercury.struct({
editor: editor,
renderer: renderer,
// if no initial value, show the editor
Expand Down
2 changes: 1 addition & 1 deletion examples/markdown/component/mdRender.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = mdRender

function mdRender(options) {
var events = input()
var state = mercury.hash({
var state = mercury.struct({
events: events,
value: mercury.value(options.value || '')
})
Expand Down
Loading

0 comments on commit f5670d4

Please sign in to comment.