-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/optimize #104
Merged
Merged
Feature/optimize #104
Changes from 21 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
3c1c317
cram build
purge 2d3c51c
minify + add version from bower
purge d0b5841
splat with curl
purge af0efc6
clean
purge 78dc45a
include plugin
purge eb91f45
move to lodash + cdns
purge fdcc6ca
cram is included for now due to npm issues
purge 2dceac6
move to bean
purge fbe28a0
build fixes
purge 3a396b4
* use require instead of curl due to path bugs.
purge bf211b3
update scaffold
purge f25c8a7
fixes
purge e158d7a
pass config
purge e6eed0e
nest options + add class back
purge b2124a7
data attrs are converted to camel case../..
purge fdc2d48
remove console
purge bc3c376
documentation
purge ab3619f
Merge pull request #103 from premasagar/feature/nest-options
adhipg 1e13c70
don't always require curl promise
purge 31bbf0e
remove cram
purge ff4b577
install stage
purge 2e4be2a
tests working again + new optimization stage
purge 02520b7
namespace rjs + don't use almond(no remote support) + working index
purge 8553cce
bower publish task
purge 7f8818c
fix config
purge 1bac5b3
preserve licences
purge 40252e8
promise test
purge aa2ea7d
ensure its actually deferred
purge 4087373
add async
purge 231b433
wrapper should only attach to window
purge 1f58634
watcher
purge 87505b2
allow plugin config to be received from bundles, and force sqwidget b…
purge 3b88121
use uglify
purge 3f52322
rename + docs
purge c5945e3
plugin tests, grunt test task, clean up
purge 0bd1724
don't stop other widgets from loading if one failes
purge 4fcd47e
src not needed any more
purge 74042ca
update scaffold
purge 9e1a3e4
update paths
purge cff21a4
caps issue
purge e4c5ba9
merge in dev
purge 6c86fe0
bundles should return initializer instead of defined Controller
purge ecec9cb
update scaffold
purge e360111
update rror
purge d229775
update README
purge 7440c22
remove unused file
purge 041249e
remove default task
purge 3df7e34
remove extraneous rendered function and use . namespacing
purge 5257a8b
update tests
purge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,5 @@ compiled/**/*.* | |
app/lib/ | ||
dist/ | ||
example-widget/ | ||
.cram/ | ||
build/ |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,114 @@ | ||
define(['./lib/bonzo/bonzo', './lib/qwery/qwery', './lib/eventEmitter/EventEmitter', 'domReady!'], | ||
function(bonzo, qwery, Emitter) { | ||
define(['require', './lib/bonzo/bonzo', './lib/qwery/qwery', 'bean', 'curl/plugin/domReady!'], | ||
function(require, bonzo, qwery, bean) { | ||
|
||
var SqwidgetCore = (function() { | ||
|
||
function SqwidgetCore() {} | ||
|
||
for (var key in Emitter.prototype) { | ||
SqwidgetCore.prototype[key] = Emitter.prototype[key]; | ||
} | ||
|
||
SqwidgetCore.prototype.packages = {}; | ||
|
||
//convert data-sqwidget to dictionary | ||
SqwidgetCore.prototype.getWidgetParams = function($el) { | ||
var data, key, val, _ref; | ||
data = {}; | ||
_ref = $el.data(); | ||
|
||
for (key in _ref) { | ||
val = _ref[key]; | ||
if (!(key.match("sqwidget"))) { | ||
continue; | ||
var key, val, | ||
data = {}, | ||
elData = $el.data(); | ||
|
||
//for compatibility data-sqwidget gets renamed data-sqwidget-url | ||
if(elData.sqwidget) { | ||
elData.sqwidgetUrl = elData.sqwidget; | ||
delete elData.sqwidget; | ||
} | ||
|
||
//convert list of names into a nested structure with val as the value | ||
var nest = function( names, val, data ) { | ||
for( var i = 0; i < names.length; i++ ) { | ||
data = data[ names[i].toLowerCase() ] = | ||
i === names.length - 1 ? val : data[ names[i] ] || {}; | ||
} | ||
key = key.replace("sqwidget", "").toLowerCase(); | ||
data[key || "url"] = val; | ||
}; | ||
|
||
for (key in elData) { | ||
val = elData[key]; | ||
if (!(key.match("^sqwidget"))) { continue; } | ||
nest(key.match(/([A-Z]?[^A-Z]*)/g).slice(0,-1), val, data); | ||
} | ||
return data; | ||
|
||
return data.sqwidget; | ||
}; | ||
|
||
SqwidgetCore.prototype.guid = function() { | ||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { | ||
return 'sqwidget-xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { | ||
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); | ||
return v.toString(16); | ||
}); | ||
}; | ||
|
||
SqwidgetCore.prototype.register = function(el) { | ||
var opts, pkg, _this = this, id = this.guid(); | ||
|
||
pkg = new Emitter(); | ||
var $el = bonzo(el).addClass('sqwidget').addClass(id); | ||
pkg.opts = opts = this.getWidgetParams($el); | ||
opts.el = pkg.el = $el; | ||
var opts, | ||
_this = this, | ||
id = this.guid(), | ||
$el = bonzo(el).addClass('sqwidget').addClass(id); | ||
opts = this.getWidgetParams($el); | ||
opts.el = $el; | ||
opts.id = id; | ||
|
||
if (!opts.url) { | ||
throw new Error("No widget source defined (set data-sqwidget-url)"); | ||
} | ||
|
||
this.packages[id] = { | ||
location: opts.url, | ||
main: 'app/index', | ||
config: opts | ||
}; | ||
return this.packages[opts.url] = opts; | ||
}; | ||
|
||
return pkg; | ||
//when the promise is resolved initialise the bundle controller | ||
SqwidgetCore.prototype.resolve = function(pkg, bundle) { | ||
if(bundle.Controller) { | ||
var widget = new bundle.Controller({ | ||
sqwidget: this, | ||
config: pkg | ||
}); | ||
|
||
//bus events | ||
bean.fire(this, "rendered:" + pkg.location); | ||
bean.fire(this, "rendered:" + pkg.id); | ||
bean.fire(pkg, "rendered"); | ||
} else { | ||
throw("controller not found for " + bundle.location); | ||
} | ||
}; | ||
|
||
SqwidgetCore.prototype.initialize = function() { | ||
var names = [], pkg, _this = this; | ||
var names = [], | ||
_this = this; | ||
|
||
for(var k in _this.packages) names.push(k); | ||
|
||
curl({ | ||
packages: _this.packages, | ||
}, names, function() { | ||
require(names, function() { | ||
var loaded = Array.prototype.slice.call(arguments); | ||
for (var i = 0; i < loaded.length; i++) { | ||
var module = loaded[i]; | ||
|
||
if(module.Controller) { | ||
var widget = new module.Controller({ | ||
sqwidget: _this | ||
}); | ||
|
||
//bus events | ||
_this.trigger("rendered:" + _this.packages[names[i]].location); | ||
_this.trigger("rendered:" + _this.packages[names[i]].id); | ||
var pkg = _this.packages[names[i]]; | ||
//if the bundle is a promise, wait for it to resolve, otherwise handle | ||
//immediately | ||
if("then" in loaded[i]) { | ||
var resolve = function(bundle) { | ||
return _this.resolve(pkg, bundle); }; | ||
loaded[i].then(resolve); | ||
} else { | ||
console.log("controller not found for " + module.location); | ||
_this.resolve(pkg, loaded[i]); | ||
} | ||
} | ||
}); | ||
}, function(err) { throw err; } ); | ||
}; | ||
|
||
return SqwidgetCore; | ||
|
||
})(); | ||
|
||
sqwidget = new SqwidgetCore(); | ||
var sqwidget = new SqwidgetCore(); | ||
|
||
bonzo(qwery('div[data-sqwidget]')).each(function(el) { | ||
sqwidget.register(el); | ||
}); | ||
|
||
sqwidget.initialize(); | ||
|
||
return sqwidget; | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,13 +21,8 @@ | |
"tests" | ||
], | ||
"dependencies": { | ||
"backbone-amd": "~1.1.0", | ||
"bonzo": "~1.3.6", | ||
"curl": "~0.8.4", | ||
"qwery": "~3.4.1", | ||
"underscore-amd": "~1.5.2", | ||
"eventEmitter": "[email protected]:Wolfy87/EventEmitter.git#master", | ||
"jquery": "~2.0.3", | ||
"momentjs": "~2.4.0" | ||
"qwery": "~3.4.1" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"baseUrl": "." | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
app/nls | ||
app/lib | ||
app/compiled | ||
build/ | ||
dist/ |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
"tests" | ||
], | ||
"dependencies": { | ||
"ractive": "~0.3.7" | ||
"ractive": "~0.3.7", | ||
"sqwidget": "~2.0.3" | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,9 @@ | |
"Simon Elliott <[email protected]>" | ||
], | ||
"main": "sqwidget.js", | ||
"files": ["sqwidget.js"], | ||
"files": [ | ||
"sqwidget.js" | ||
], | ||
"engines": { | ||
"node": ">= 0.8.0" | ||
}, | ||
|
@@ -18,7 +20,6 @@ | |
"bugs": { | ||
"url": "http://github.com/premagasar/sqwidget/issues" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"grunt": "latest", | ||
"grunt-contrib-connect": "latest", | ||
|
@@ -36,10 +37,14 @@ | |
"karma-mocha": "~0.1.0", | ||
"karma-sinon": "0.0.1", | ||
"karma-chai-plugins": "~0.1.3", | ||
"grunt-contrib-uglify": "~0.2.5", | ||
"grunt-contrib-concat": "~0.3.0", | ||
"grunt-init": "# This is because of the yes option. PR raised", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So are we doing the comments in the json thing? |
||
"grunt-init": "https://github.com/papercreatures/grunt-init/tarball/master" | ||
}, | ||
"scripts": { | ||
"prepublish": "make dist", | ||
"install": "pushd node_modules/cram && bower install && popd", | ||
"postinstall": "./grunt-scaffold/install.sh", | ||
"build": "make build", | ||
"test": "make test" | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Namespacing using dots?
And in that case, do we need the last one?