Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update README.md

Add an example with a custom mixin.
  • Loading branch information...
commit 27399327f0d8b6a8d11ef4fe3b8a800f39c617e5 1 parent d871f87
@fblee fblee authored fblee committed
Showing with 38 additions and 1 deletion.
  1. +38 −1 README.md
View
39 README.md
@@ -12,7 +12,7 @@ Key points
Examples
========
-
+Creating a user model that can authenticate:
```javascript
models.user = function () {
@@ -70,6 +70,43 @@ fred.whenEqual('authenticated', true, function () {
```
+Encapsulating some functionality in a custom mixin:
+```javascript
+
+lib.remoteLoggable = function(_public, _protected, base_url) {
+ _protected.log = function (message) {
+ return $.ajax({ // requires jQuery/Zepto
+ url: '/client/logger', // server must implement this endpoint
+ data: {message: message},
+ type: 'POST',
+ dataType: 'json',
+ error: function (error) {
+ console.log("Failed with error (" + error + ") trying to log: ", message);
+ }
+ });
+ };
+
+ return _public;
+};
+
+models.user = function (first_name) {
+ var _public = {}, _protected = {};
+
+ lib.remoteLoggable(_public, _protected);
+
+ _public.greet = function () {
+ _protected.log("We totally said hello to " + first_name);
+ return "Hello world, and hello " + first_name + "!";
+ };
+
+ return _public;
+};
+
+var lee = models.user("Lee");
+lee.greet(); // a message also gets POSTed to our server.
+
+```
+
TODO
====
Please sign in to comment.
Something went wrong with that request. Please try again.