Last active
December 29, 2015 14:59
-
-
Save stonly/7687999 to your computer and use it in GitHub Desktop.
Would this work and does it make sense what im trying to accomplish?
This file contains 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
/* | |
scope -> non functions and non constats are regular objects, no functions allowed | |
services -> all functions are sent through a service that executes on the server (nodejs in this example but could be python. could also be a hosted service) | |
*/ | |
angular.module('MVapp', []) | |
.factory('Service', function($http, $q){ | |
return { | |
_: function(){ | |
$http.post('/factory', {a: arguments}) | |
.then(function(resp){ | |
return resp; | |
}, function(resp){ | |
return $q.reject(resp); | |
}); | |
} | |
} | |
}); | |
.controller("MVappCtrl1", ["$scope", "Service", function($scope, Service){ | |
$scope.sum = 0; | |
$scope.addFun = function add(a, b){ | |
return z_(arguments); | |
} | |
$scope.addFun(1,2); | |
$scope.secretWord = function secretWord(){ | |
return z_(arguments); | |
} | |
var z_ = function(){ | |
var ns = Service._([arguments.callee.name].concat(arguments)); | |
if(ns.scope){ | |
for(var k in ns.scope){ | |
$scope[k] = ns[k]; | |
} | |
return; | |
} else { | |
return ns | |
} | |
} | |
}]); |
This file contains 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
<!DOCTYPE html> | |
<html ng-app='MVapp'> | |
<head></head> | |
<body ng-controller='MVappCtrl1'> | |
<span> 1 + 2 = {{sum}} </span> | |
<br> | |
<span> The secret word is '{{secretWord()}}'!</span> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.3/angular.min.js"></script> | |
<script src="client.js"></script> | |
</body> | |
</html> |
This file contains 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 express = require('express'); | |
var api = express(); | |
api.post('/factory', function(req, res) { | |
res.send(processReq(req.body)); | |
}); | |
api.listen(80); | |
var processReq = function(r){ | |
var fun = r.a[0]; | |
have[fun].apply(this, a.splice(1)) | |
} | |
var have = { | |
add : function(a,b){ | |
return { scope : { sum : a + b } } | |
}, | |
secretWord : function(){ | |
//do magic | |
return 'abracadabra' | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment