Skip to content

Commit

Permalink
Live Examples (#3138)
Browse files Browse the repository at this point in the history
Removed redundant statement
  • Loading branch information
rafde authored and ahumphreys87 committed Aug 23, 2016
1 parent be69b37 commit a0935d5
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions docs/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ var MyView = Mn.View.extend({
});
```

[Live example](https://jsfiddle.net/marionettejs/k93pejyb/)

When we instantiate `MyView`, each instance will be given a `.bg-success` class
with a `myRegion` region created on the `.my-region` element.

Expand Down Expand Up @@ -99,20 +101,19 @@ var MyView = Mn.View.extend({
},

alert: function() {
window.alert('model changed');
console.log('model changed');
}
});
```

[Live example](https://jsfiddle.net/marionettejs/nn1754fc/)

As we can see, almost all of the attributes here can be worked out dynamically.
In most cases, Marionette will call the function once at instantiation, or first
render, and preserve the value throughout the lifetime of the View. There are
some exceptions to this rule - these will be referred to with their respective
documentation.

There are some exceptions to this general rule that will be documented in the
relevant places.

### Function Context

When using functions to set attributes, Marionette will assign the instance of
Expand Down Expand Up @@ -189,9 +190,11 @@ var view = new MyView({
foo: 'some text'
});

view.checkOption(); // prints 'some text'
console.log(view.checkOption()); // prints 'some text'
```

[Live example](https://jsfiddle.net/marionettejs/6n02ex1m/)

### The `getOption` Method

To access an option, we use the `getOption` method.
Expand All @@ -213,6 +216,8 @@ var myView = new MyView({
});
```

[Live example](https://jsfiddle.net/marionettejs/ekvb8wwa/)

This only works for custom options - arguments that belong to the standard
Backbone/Marionette attributes, such as `model` and `collection`, are not
accessible via `getOption` and should be accessed as just `view.model` or
Expand Down Expand Up @@ -246,6 +251,8 @@ console.log(myObject.something);
console.log(myObject.getOption('another'));
```

[Live example](https://jsfiddle.net/marionettejs/ub510cbx/)

In this example, `model` and `something` are directly available on the
`MyObject` instance, while `another` must be accessed via `getOption`. This is
handy when you want to add extra keys that will be used heavily throughout the
Expand Down

0 comments on commit a0935d5

Please sign in to comment.