architect 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +26 -0
- data/app/assets/javascripts/architect.coffee.erb +13 -0
- data/lib/architect/version.rb +1 -1
- data/static/architect.min.js +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5d72efb3fd9592e10ff2e9a2653338a327a3752
|
4
|
+
data.tar.gz: 25185539fe7650a62973f6938877c3b73ce99511
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4862a67359d4f0020c3d129565422fb188d0a00e3bf72ae6cd220925a16b780cff8764256cdbedcb7b15d37e5bb854ea624af97426875a229ddee7726b21314
|
7
|
+
data.tar.gz: 609ffe41e38be243fc29e62e22fdcccc0c7568a39656d7aff6eb471ce8baa1ef86755684e75ae750935e672984fabce520ac512634f9a5352debbe10a652c242
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -121,6 +121,32 @@ Architect.jsonpOn('profile', 'https://api.github.com/users/etiennelem', function
|
|
121
121
|
|
122
122
|
Alias for `Architect.workOn(jobName, url, 'jsonp', callback)`.
|
123
123
|
|
124
|
+
## Custom workers
|
125
|
+
You can use Architect with your own workers. Just remember that if you want to be compatible with all the old browsers you need to optionally provide a fallback function that replicates your worker’s work.
|
126
|
+
|
127
|
+
### workFrom
|
128
|
+
```js
|
129
|
+
// workers/foozle.js
|
130
|
+
addEventListener('message', function(e) {
|
131
|
+
data = (e.data + 'zle').toUpperCase()
|
132
|
+
postMessage(data)
|
133
|
+
})
|
134
|
+
```
|
135
|
+
|
136
|
+
```js
|
137
|
+
// application.js
|
138
|
+
|
139
|
+
// Replicates workers/foozle.js, but in the main thread
|
140
|
+
var foozleFallback = function(data) {
|
141
|
+
return (data + 'zle').toUpperCase()
|
142
|
+
}
|
143
|
+
|
144
|
+
Architect.workFrom('workers/foozle.js', 'foo', foozleFallback, function(data) {
|
145
|
+
console.log(data)
|
146
|
+
// => FOOZLE
|
147
|
+
})
|
148
|
+
```
|
149
|
+
|
124
150
|
## Setup
|
125
151
|
### Rails
|
126
152
|
1. Add `gem 'architect'` to your Gemfile.
|
@@ -46,3 +46,16 @@ jobs = {}
|
|
46
46
|
@Architect.proxyOn = (jobName, data, callback) => @Architect.workOn(jobName, data, 'proxy', callback)
|
47
47
|
@Architect.ajaxOn = (jobName, url, callback) => @Architect.workOn(jobName, url, 'ajax', callback)
|
48
48
|
@Architect.jsonpOn = (jobName, url, callback) => @Architect.workOn(jobName, url, 'jsonp', callback)
|
49
|
+
|
50
|
+
# Custom workers
|
51
|
+
@Architect.workFrom = (workerPath, data, fallback=null, callback) =>
|
52
|
+
if @Architect.SUPPORT_WORKER
|
53
|
+
worker = new Worker(workerPath)
|
54
|
+
worker.postMessage(data)
|
55
|
+
worker.addEventListener 'message', (e) ->
|
56
|
+
worker.terminate()
|
57
|
+
callback(e.data)
|
58
|
+
else if fallback
|
59
|
+
callback(fallback(data))
|
60
|
+
else
|
61
|
+
console.warn "No fallback provided for #{workerPath}"
|
data/lib/architect/version.rb
CHANGED
data/static/architect.min.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
!function(){this.Architect={},this.Architect.VERSION="0.0.
|
1
|
+
!function(){this.Architect={},this.Architect.VERSION="0.0.6"}.call(this),function(){this.Architect.Worker=function(){function t(){this.callbacks={},this.callbacksQueue={}}return t.prototype.addEventListener=function(t,r){var e;return this.callbacks[t]=r,(e=this.callbacksQueue[t])?(delete this.callbacksQueue[t],this.dispatch(t,e)):void 0},t.prototype.dispatch=function(t,r){return this.callbacks[t]?this.callbacks[t]({data:r}):this.callbacksQueue[t]=r},t.prototype.handleRequest=function(t){return this.dispatch("message",t)},t.prototype.terminate=function(){},t}()}.call(this),function(){var t,r={}.hasOwnProperty,e=function(t,e){function n(){this.constructor=t}for(var o in e)r.call(e,o)&&(t[o]=e[o]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};this.Architect.AjaxWorker=function(r){function n(){return t=n.__super__.constructor.apply(this,arguments)}return e(n,r),n.prototype.postMessage=function(t){var r,e=this;return r=new XMLHttpRequest,r.open("GET",t),r.onreadystatechange=function(){return 4===r.readyState&&200===r.status?e.handleRequest(r.responseText):void 0},r.send()},n}(this.Architect.Worker)}.call(this),function(){var t={}.hasOwnProperty,r=function(r,e){function n(){this.constructor=r}for(var o in e)t.call(e,o)&&(r[o]=e[o]);return n.prototype=e.prototype,r.prototype=new n,r.__super__=e.prototype,r};this.Architect.JSONPWorker=function(t){function e(){e.__super__.constructor.call(this),window.jsonpID||(window.jsonpID=0)}return r(e,t),e.prototype.postMessage=function(t){var r,e,n=this;return e=document.createElement("script"),r="architect_jsonp"+ ++window.jsonpID,window[r]=function(t){return delete window[r],document.head.removeChild(e),n.handleRequest(t)},e.src=this.appendQuery(t,"callback="+r),document.head.appendChild(e)},e.prototype.appendQuery=function(t,r){return(t+"&"+r).replace(/[&?]{1,2}/,"?")},e}(this.Architect.Worker)}.call(this),function(){var t,r={}.hasOwnProperty,e=function(t,e){function n(){this.constructor=t}for(var o in e)r.call(e,o)&&(t[o]=e[o]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};this.Architect.ProxyWorker=function(r){function n(){return t=n.__super__.constructor.apply(this,arguments)}return e(n,r),n.prototype.postMessage=function(t){return this.handleRequest(t)},n}(this.Architect.Worker)}.call(this),function(){var t,r,e=this;this.Architect.SUPPORT_WORKER=!!window.Worker,this.Architect.WORKERS={proxy:{polyfill:this.Architect.ProxyWorker,workerPath:"architect/proxy_worker.min.js"},ajax:{polyfill:this.Architect.AjaxWorker,workerPath:"architect/ajax_worker.min.js"},jsonp:{polyfill:this.Architect.JSONPWorker,workerPath:"architect/jsonp_worker.min.js"}},r=function(t){return this.Architect.SUPPORT_WORKER?new Worker(this.Architect.WORKERS[t].workerPath):new this.Architect.WORKERS[t].polyfill},this.Architect.work=function(t,e,n){var o;return o=r(e),o.postMessage(t),o.addEventListener("message",function(t){return o.terminate(),n(t.data)})},this.Architect.proxy=function(t,r){return e.Architect.work(t,"proxy",r)},this.Architect.ajax=function(t,r){return e.Architect.work(t,"ajax",r)},this.Architect.jsonp=function(t,r){return e.Architect.work(t,"jsonp",r)},t={},this.Architect.workOn=function(e,n,o,c){var i,s,a=this;return this.workOnCallback=c,i=!!t[e],s=t[e]||(t[e]=r(o)),s.postMessage(n),i?void 0:s.addEventListener("message",function(t){return a.workOnCallback(t.data)})},this.Architect.endJob=function(r){var e;if(e=t[r])return e.terminate(),delete t[r]},this.Architect.proxyOn=function(t,r,n){return e.Architect.workOn(t,r,"proxy",n)},this.Architect.ajaxOn=function(t,r,n){return e.Architect.workOn(t,r,"ajax",n)},this.Architect.jsonpOn=function(t,r,n){return e.Architect.workOn(t,r,"jsonp",n)},this.Architect.workFrom=function(t,r,n,o){var c;return null==n&&(n=null),e.Architect.SUPPORT_WORKER?(c=new Worker(t),c.postMessage(r),c.addEventListener("message",function(t){return c.terminate(),o(t.data)})):n?o(n(r)):console.warn("No fallback provided for "+t)}}.call(this);
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: architect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Etienne Lemay
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coffee-rails
|