Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity Relationships #13

Open
wants to merge 2 commits into
base: cl/linker-architecture
Choose a base branch
from

Conversation

cowboyd
Copy link
Member

@cowboyd cowboyd commented Dec 11, 2018

This adds a DB example that contains a number of tables each of which have rows that link to each other. This uses the ability to link anywhere in the store to create a factory method that creates entities elswhere in the store.

In this example, the Blog record has a reference to a Person which is the author. The factory for author attribute of a blog, creates that person in the database, and then returns that person.

It isn't just enough to be able to link to entitities from across a
store. You also need to be able to create them in concert with each
other. This presents a unique difficulty in microstates where every
transition is chained off of an "owner" object. How then, do you
operate on objets that might not share a common ancestor?

The answer is to introduce a new primitive: the transaction. This
allows you to pass as many microstates into a transaction as you want,
and with each operation in the transaction, the atom is kept in sync
so that each microstate in a transaction is talking about the same
universe. So, for example, as part of the blog creation process, we
want to first create a person and then a assign that person to the
blog's s author, we need to call create on the people table, and
then set the relationship on the person.

Each transaction has a subject and any number of members, that will be
kept in sync for the operation wich is implemented using the monadic
flatMap operator. E.g.

import Txn from 'transaction';

let txn = Txn(subject, other, yetAnother)
  .flatMap(([subject, other, yetAnother]) => subject.transition(other, yetAnother))

this will take the atom from subject and use it as the basis for
all participants in the transaction. In this case other, and
yetAnother. So that when we flatMap, all of them are operating
against the same data.

Note: the argument to the flatMap function is the transaction
itself, but it destructures to its members.

Also, every participant in the transaction is scoped to itself as
owner, so that subject.transition() will return subject.

While rock-solid, this makes for an awkward API, so we'll still need
to find out how to do the interior design to make it more
pleasant. Still, I think that can come later.

  • use transactions in more places, specifically in a transition.
  • currently transaction is eager, but could be made lazy.

@cowboyd cowboyd force-pushed the cl/linker-architecture branch from 1a91ddf to 19ffae1 Compare December 11, 2018 19:34
@cowboyd cowboyd force-pushed the cl/entity-relationships branch from ae45efd to 397360d Compare December 11, 2018 19:36
This adds a `DB` example that contains a number of tables each of
which have rows that link to each other. This uses the ability to link
anywhere in the store to create a factory method that creates entities
elswhere in the store.

In this example, the `Blog` record has a reference to a `Person` which
is the author. The factory for author attribute of a blog, creates
that person in the database, and then returns that person.
@cowboyd cowboyd force-pushed the cl/entity-relationships branch from 397360d to 84fd6ec Compare December 11, 2018 19:53
It isn't just enough to be able to link to entitities from across a
store. You also need to be able to create them in concert with each
other. This presents a unique difficulty in microstates where every
transition is chained off of an "owner" object. How then, do you
operate on objets that might not share a common ancestor?

The answer is to introduce a new primitive: the transaction. This
allows you to pass as many microstates into a transaction as you want,
and with each operation in the transaction, the atom is kept in sync
so that each microstate in a transaction is talking about the same
universe. So, for example, as part of the blog creation process, we
want to first create a person and then a assign that person to the
blog's s author, we need to call _create_ on the people table, and
then _set_ the relationship on the person.

Each transaction has a subject and any number of members, that will be
kept in sync for the operation wich is implemented using the monadic
`flatMap` operator. E.g.

```js
import Txn from 'transaction';

let txn = Txn(subject, other, yetAnother)
  .flatMap(([subject, other, yetAnother]) => subject.transition(other, yetAnother))
```

this will take the `atom` from `subject` and use it as the basis for
_all_ participants in the transaction. In this case `other`, and
`yetAnother`. So that when we flatMap, all of them are operating
against the same data.

> Note: the argument to the flatMap function is the transaction
  itself, but it destructures to its members.

Also, every participant in the transaction is scoped to itself as
owner, so that subject.transition() will return subject.

While rock-solid, this makes for an awkward API, so we'll still need
to find out how to do the interior design to make it more
pleasant. Still, I think that can come later.

- [ ] use transactions in more places, specifically in a transition.
- [ ] currently transaction is eager, but could be made lazy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant