Last active
August 29, 2015 14:01
-
-
Save pasberth/cd723ce200216e8c5d88 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (assume JSON) | |
| (assume newVue) | |
| (assume newXMLHttpRequest) | |
| (newVue (object | |
| el "#demo" | |
| data (object branch "master") | |
| created (^ () (seq | |
| (assume this) | |
| ((. this $watch) "branch" (^ () ((. this fetchData)))))) | |
| filters (object | |
| truncate (^ v (seq | |
| (let newline ((. v indexOf) "\n")) | |
| (match newline | |
| (^ 0 v) | |
| (^ -1 v) | |
| (^ _ ((. v slice) 0 newline))))) | |
| formatDate (^ (v _) v)) | |
| methods (object | |
| fetchData (^ () (seq | |
| (assume this) | |
| (let xhr (newXMLHttpRequest)) | |
| (let self this) | |
| ((. xhr open) "GET" (str.add "https://api.github.com/repos/yyx990803/vue/commits?per_page=3&sha=" (. self branch))) | |
| (:= (. xhr onload) (^ () | |
| (:= (. self commits) ((. JSON parse) (. xhr responseText))))) | |
| ((. xhr send))))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (val JSON (obj parse (-> 'a 'b))) | |
| (val newVue (-> (obj methods (obj fetchData (-> () 'a)) | |
| el "#demo" | |
| data (obj branch "master") | |
| created (-> () 'b) | |
| filters (obj formatDate (-> ('c 'd) 'c) | |
| truncate (-> (obj slice (-> (0.0 (| 0.0 -1.0 'e)) 'f) | |
| indexOf (-> "\n" (| 0.0 -1.0 'e))) | |
| (| (obj slice (-> (0.0 (| 0.0 -1.0 'e)) 'f) | |
| indexOf (-> "\n" (| 0.0 -1.0 'e))) | |
| (obj slice (-> (0.0 (| 0.0 -1.0 'e)) 'f) | |
| indexOf (-> "\n" (| 0.0 -1.0 'e))) | |
| 'f)))) | |
| 'g)) | |
| (val newXMLHttpRequest (-> () | |
| (obj onload (mutable (-> () ())) | |
| responseText 'a | |
| open (-> ("GET" string) 'b) | |
| send (-> () 'c)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function () { | |
| 'use strict'; | |
| var Binal; | |
| Binal = require('binal-runtime'); | |
| return newVue({ | |
| methods: { | |
| fetchData: function () { | |
| var xhr; | |
| xhr = newXMLHttpRequest(); | |
| var self; | |
| self = this; | |
| xhr.open('GET', 'https://api.github.com/repos/yyx990803/vue/commits?per_page=3&sha=' + self.branch); | |
| xhr.onload = function () { | |
| var _tmp0; | |
| _tmp0 = xhr.responseText; | |
| if (_tmp0 instanceof Binal.Tuple) | |
| self.commits = JSON.parse.apply(JSON, _tmp0.xs); | |
| else | |
| self.commits = JSON.parse(_tmp0); | |
| return self.commits; | |
| }; | |
| return xhr.send(); | |
| } | |
| }, | |
| el: '#demo', | |
| data: { branch: 'master' }, | |
| created: function () { | |
| return this.$watch('branch', function () { | |
| return this.fetchData(); | |
| }); | |
| }, | |
| filters: { | |
| formatDate: function (v, _) { | |
| if (!(arguments.length === 2)) | |
| _ = Binal.mkTuple(Array.prototype.slice.call(arguments, 1)); | |
| return v; | |
| }, | |
| truncate: function (v) { | |
| var _tmp0; | |
| var newline; | |
| newline = v.indexOf('\n'); | |
| if (newline === 0) | |
| return function () { | |
| return v; | |
| }(newline); | |
| else if (newline === -1) | |
| return function () { | |
| return v; | |
| }(newline); | |
| else if (newline) { | |
| _tmp0 = function (_) { | |
| if (!(arguments.length === 1)) | |
| _ = Binal.mkTuple(Array.prototype.slice.call(arguments, 0)); | |
| if (newline instanceof Binal.Tuple) | |
| return v.slice.apply(v, [0].concat(newline.xs)); | |
| else | |
| return v.slice(0, newline); | |
| }; | |
| if (newline instanceof Binal.Tuple) | |
| return _tmp0.apply(this, newline.xs); | |
| else | |
| return _tmp0(newline); | |
| } else | |
| throw new Binal.NonExhaustivePatterns('Non-exhaustive patterns in match'); | |
| } | |
| } | |
| }); | |
| }()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Vue = require("vue"); | |
| function newVue(obj) { | |
| return new Vue(obj); | |
| } | |
| function newXMLHttpRequest() { | |
| return new XMLHttpRequest(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment