Skip to content

Commit 867d731

Browse files
author
Josh Callender
committed
started writing docs for model
1 parent 5cbc590 commit 867d731

File tree

6 files changed

+80
-7
lines changed

6 files changed

+80
-7
lines changed

_config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@ github_username: rendrjs
1010
# Build settings
1111
markdown: redcarpet
1212
highlighter: pygments
13-

_includes/navigation.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ <h3>
88
</h3>
99

1010
<ul>
11-
<li><a href="/model#initialize">initialize</a></li>
12-
<li><a href="/model#render">render</a></li>
11+
<li><a href="/model#constructor">constuctor</a></li>
12+
<li><a href="/model#jsonKey">jsonKey</a></li>
13+
<li><a href="/model#parse">parse</a></li>
14+
<li><a href="/model#store">store</a></li>
15+
<li><a href="/model#url">url</a></li>
1316
</ul>
1417

1518
<h3><a href="/#examples">Examples</a></h3>

_sass/_base.scss

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ pre {
170170
}
171171
}
172172

173-
174-
175173
/**
176174
* Clearfix
177175
*/
@@ -184,8 +182,6 @@ pre {
184182
}
185183
}
186184

187-
188-
189185
/**
190186
* Icons
191187
*/
@@ -203,3 +199,6 @@ pre {
203199
}
204200
}
205201

202+
h1 {
203+
font-size: 2.5em;
204+
}

_sass/_layout.scss

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,23 @@
206206

207207
.content {
208208
max-width: 1000px;
209+
210+
hr {
211+
margin-bottom: 10px;
212+
background-color: #ccc;
213+
color: #ccc;
214+
border-width: 0;
215+
height: 1px;
216+
}
217+
218+
h3 {
219+
margin-top: 40px;
220+
221+
> span {
222+
font-weight: 300;
223+
font-size: 0.8em;
224+
margin-left: 15px;
225+
}
226+
}
227+
209228
}

model/.index.md.swp

12 KB
Binary file not shown.

model/index.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
layout: content
3+
title: "Model - RendrJS"
4+
---
5+
6+
# Model
7+
8+
Rendr models are extenions on [Backbone Models](http://backbonejs.org#Model). They are configured to run on the client and server, however some of the funcitonality works a little different between the two. Ideally in a project you don't need to worry about these changes, but here's some documentation on how they function and some of the differences between the two states that they'll be running in.
9+
10+
11+
### constructor <span>new Model([attributes], [options])</span>
12+
<hr />
13+
14+
The **constructor** will create an instance of a Rendr Model. The options are expecting a reference to the app object, this is used to hook into the sync functionality. The constructor also invokes the parent Backbone initialization, and finally stores the instance in the model store.
15+
16+
17+
### jsonKey <span>Model.jsonKey</span>
18+
<hr />
19+
20+
**jsonKey** is the JSON root of the response from the API. This will automatically [parse](#parse) an API response with a root key.
21+
22+
```js
23+
Model.jsonKey = 'user';
24+
25+
// expected data format from the API
26+
// this will then be parsed and set onto the model
27+
{
28+
user: {
29+
id: 1,
30+
name: 'Tester'
31+
}
32+
}
33+
```
34+
35+
36+
### parse <span>Model.parse(response, [options])</span>
37+
<hr />
38+
39+
**parse** is called when data is returned from a [fetch](http://backbonejs.org#Model-fetch) request. The *response* is a json object, and the value returned from this function will be set as the attributes of the model. If your API is returning a root object in the key, you can set the [jsonKey](#jsonkey) to return the attributes, withouth having to override the default functionality.
40+
41+
42+
43+
### store <span>Model.store()</span>
44+
<hr />
45+
46+
This will save the data to the model store. This data is retrieved when the veiws are being constructed. This saves on requests as well, as the fetch function will check the store before creating the AJAX request to the server. Store also has a default trigger setup on the `change` event of the `idAttribute`. This means, if you modify the ID it will re-store the data. Since the store is referencing the instance of the model, you *don't* need to setup a change event on the entire model, as it will get those changes automatically.
47+
48+
49+
### url <span>Model.url or Model.url()</span>
50+
<hr />
51+
52+
This has the same functionality as the [Backbone property](http://backbonejs.org#Model-url) with the add ability of passing a string with interpolation. For example: `'/model/:someAttribute'`.
53+

0 commit comments

Comments
 (0)