Permalink
Browse files

Use type convention in examples. Link to introduction video.

  • Loading branch information...
michaellperry committed Sep 3, 2015
1 parent 5038e4c commit d647b5d679f6ede99bf9951ab0cbdb7f018724ef
Showing with 35 additions and 9 deletions.
  1. +17 −4 README.md
  2. +11 −5 mutability.md
  3. +7 −0 security.md
View
@@ -1,6 +1,10 @@
# Jinaga
JSON Messaging Platform
+<iframe src="https://player.vimeo.com/video/137919088" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
+
+Get a quick [video introduction](https://vimeo.com/137919088) to Jinaga.
+
- [Mutablity](https://github.com/michaellperry/jinaga/blob/master/mutability.md)
- [Security](https://github.com/michaellperry/jinaga/blob/master/security.md)
- [Synchronization](https://github.com/michaellperry/jinaga/blob/master/synchronization.md)
@@ -21,7 +25,9 @@ var Jinaga = require ('jinaga');
var j = new Jinaga();
j.fact({
+ type: "Task",
list: {
+ type: "TodoList",
name: "Chores"
},
description: "Take out the trash"
@@ -32,6 +38,7 @@ This code represents two messages. The first is:
```JavaScript
var chores = {
+ type: "TodoList",
name: "Chores"
};
```
@@ -40,6 +47,7 @@ The second is:
```JavaScript
var trash = {
+ type: "Task",
list: chores,
description: "Take out the trash"
};
@@ -54,6 +62,7 @@ Now that you can express that **chores** is a predecessor of **trash**, you migh
```JavaScript
function tasksInList(l) {
return {
+ type: "Task",
list: l
};
}
@@ -73,6 +82,7 @@ Now if I add a new task to the list, the **taskAdded** function will be called.
```JavaScript
var dishes = {
+ type: "Task",
list: chores,
description: "Empty the dishwasher"
};
@@ -100,6 +110,7 @@ Now I want to mark a task completed. Let's capture that as another message.
```JavaScript
j.fact({
+ type: "TaskCompleted",
task: trash,
completed: true
});
@@ -110,6 +121,7 @@ Let's write a template that matches this message for a given task.
```JavaScript
function taskIsNotCompleted(t) {
return j.not({
+ type: "TaskCompleted",
task: t,
completed: true
});
@@ -120,10 +132,10 @@ Now we can write a query so that only the uncompleted tasks match the template.
```JavaScript
function uncompletedTasksInList(l) {
- return {
- list: l,
- __where: [taskIsNotCompleted]
- };
+ return j.where({
+ type: "Task",
+ list: l
+ }, [taskIsNotCompleted]);
}
j.watch(chores, [uncompletedTasksInList], taskAdded);
@@ -143,6 +155,7 @@ Now when you complete a task, the taskRemoved function will be called to remove
```JavaScript
j.fact({
+ type: "TaskCompleted",
task: dishes,
completed: true
});
View
@@ -8,6 +8,7 @@ Capture each change to a mutable property as individual messages. For example, t
```JavaScript
var myBook = {
+ type: "Book",
id: j.unique()
};
@@ -18,6 +19,7 @@ The next message is the initial title of the book.
```JavaScript
var initialTitle = {
+ type: "BookTitle",
book: myBook,
title: "All's Well that Ends Well"
};
@@ -29,6 +31,7 @@ To change the book's title, issue another message. The message should refer to t
```JavaScript
var revisedTitle = {
+ type: "BookTitle",
book: myBook,
title: "War and Peace",
prior: [initialTitle]
@@ -42,15 +45,16 @@ To watch for changes to mutable properties, create a query matching change messa
```JavaScript
funciton titleIsCurrent(t) {
return j.not({
+ type: "BookTitle",
prior: t
});
}
function bookTitle(b) {
- return {
- book: b,
- __where: [titleIsCurrent]
- };
+ return j.where({
+ type: "BookTitle",
+ book: b
+ }, [titleIsCurrent]);
}
function titleAdded(bookTitle) {
@@ -71,9 +75,10 @@ Because every change to a mutable property records the previous messages, we can
```JavaScript
var anotherRevisedTitle = {
+ type: "BookTitle",
book: myBook,
title: "All's Fair in Love and War",
- prior: [initialTitle]
+ prior: [initialTitle] // Notice the same prior as before
};
j.fact(anotherRevisedTitle);
@@ -108,6 +113,7 @@ Notice that the **prior** predecessor is an array. This allows a message to refe
```JavaScript
j.fact({
+ type: "BookTitle",
book: myBook,
title: "War and Peace",
prior: titleCandidates
View
@@ -4,6 +4,7 @@ A message can be used to identify an individual user of the application. Such a
```JavaScript
var user = {
+ type: "User",
__publicKey: "...nbZ15mk0zNC/WJWjM3vDRB3"
}
```
@@ -24,6 +25,7 @@ To send a private message to an individual, set the individual as the **__to** p
```JavaScript
var secret {
+ type: "Secret",
__to: flynn,
password: "Reindeer Flotilla"
};
@@ -39,6 +41,7 @@ To sign a message, set your own user object as the **__from** property of the me
```JavaScript
var email {
+ type: "Email",
__to: alan1,
__from: flynn,
content: "It's all in the wrists."
@@ -55,11 +58,13 @@ A shared key can be used to encrypt messages that multiple people can all see. S
```JavaScript
var project {
+ type: "Project",
name: "Space Paranoids",
__locked: true
};
var flynnPrivilege {
+ type: "Privilege",
__admin: project,
__to: flynn,
__from: flynn
@@ -75,6 +80,7 @@ The successor must be encrypted. So it must have a **__to** predecessor. The adm
```JavaScript
q.fact({
+ type: "Privilege",
__write: project,
__to: alan1,
__from: flynn
@@ -87,6 +93,7 @@ Now that Flynn has write privileges to the project, he can create successors.
```JavaScript
q.fact({
+ type: "Instruction",
__in: project,
__from alan1,
program: "TRON"

0 comments on commit d647b5d

Please sign in to comment.