Skip to content

Commit

Permalink
Merge pull request #94 from andreip/master
Browse files Browse the repository at this point in the history
Update tutorial.md and code from tutorial/ for new delorian.js
  • Loading branch information
f committed Mar 16, 2016
2 parents 7874c7a + be85784 commit f0dc059
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
9 changes: 5 additions & 4 deletions docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ First of all, let's create the DOM (view) we'll need.
<script src="https://cdn.rawgit.com/deloreanjs/delorean/master/dist/delorean.min.js"></script>
</head>
<body>
<ul id="list"></ul>
<button id="addItem">Add Random Item</button>
<ul id="list"></ul>

<script src="js/app.js"></script>
</body>
Expand Down Expand Up @@ -90,7 +90,7 @@ with arguments.
Also you have to call `this.emit('change')` when you update your data.

```javascript
var MyAppStore = DeLorean.Flux.createStore({
var myStore = DeLorean.Flux.createStore({
list: [],
actions: {
// Remember the `dispatch('addItem')`
Expand All @@ -103,9 +103,10 @@ var MyAppStore = DeLorean.Flux.createStore({
this.emit('change');
}
});
var myStore = new MyAppStore();
```

Make sure you put this code before the one from step 2 though, because we were using `myStore` in creating the `MyAppDispatcher`, and that will keep a reference to the store internally.

### Step 4: Completing the Cycle: Views

Now everything seems okay, but **we didn't completed the cycle yet**.
Expand All @@ -117,7 +118,7 @@ var list = document.getElementById('list');
myStore.onChange(function () {
list.innerHTML = ''; // Best thing for this example.

myStore.store.list.forEach(function (item) {
myStore.list.forEach(function (item) {
var listItem = document.createElement('li');
listItem.innerHTML = item;
list.appendChild(listItem);
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorial/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<script src="http://rawgit.com/f/delorean/master/dist/delorean.min.js"></script>
</head>
<body>
<ul id="list"></ul>
<button id="addItem">Add Random Item</button>
<ul id="list"></ul>

<script src="js/app.js"></script>
</body>
Expand Down
5 changes: 2 additions & 3 deletions examples/tutorial/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var ActionCreator = {
}
};

var MyAppStore = DeLorean.Flux.createStore({
var myStore = DeLorean.Flux.createStore({
list: [],
actions: {
// Remember the `dispatch('addItem')`
Expand All @@ -22,7 +22,6 @@ var MyAppStore = DeLorean.Flux.createStore({
this.emit('change');
}
});
var myStore = new MyAppStore();

var MyAppDispatcher = DeLorean.Flux.createDispatcher({
addItem: function (data) {
Expand All @@ -42,7 +41,7 @@ var list = document.getElementById('list');
myStore.onChange(function () {
list.innerHTML = ''; // Best thing for this example.

myStore.store.list.forEach(function (item) {
myStore.list.forEach(function (item) {
var listItem = document.createElement('li');
listItem.innerHTML = item;
list.appendChild(listItem);
Expand Down

0 comments on commit f0dc059

Please sign in to comment.