Last active
December 11, 2015 02:08
-
-
Save aaronj1335/4527927 to your computer and use it in GitHub Desktop.
configurable widget
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 would live in auxl | |
define([ | |
'vendor/jquery', | |
'configuration' | |
], function($, configuration) { | |
return function(options) { | |
var name = options.name; | |
this.configuration = | |
$.extend(true, this.configuration, configuration[name]); | |
}; | |
}); |
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 would be generated server-side similar to the 'strings' module, | |
// there wouldn't actually be a configuration.js file | |
define([], function(){ | |
return { | |
viewwithfourslots: {/*...*/} | |
} | |
}) |
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
define([ | |
'vendor/underscore', | |
'gloss/view', | |
'auxl/asconfigurable', | |
'module' | |
], function(_, View, asConfigurable, module) { | |
var ViewWithFourSlots = View.extend({ | |
defaults: {/*...*/}, | |
configuration: { | |
// this is where the defaults go | |
}, | |
init: function() { | |
/* ... */ | |
} | |
}); | |
asConfigurable.call(ViewWithFourSlots.prototype, { | |
name: _.last(module.id.split('/')) | |
}); | |
return ViewWithFourSlots; | |
}); |
updated w/ a note about setting default options.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this would work for a bare-bones implementation of the configurable ui element. a few things to note:
viewwithfourslots
(regardless of what we name thatvar
in the file)configurable.js
such thatthis.configuration
is a class that's been mixed-in w/assettable.js
, enabling stuff likethis.configuration.get('foo.bar')
View
, then accessing the configuration from w/in the view's template is as easy asthis.configuration
this of course doesnt address anything about how we get the configuration down to the client. that'd involve a context processor, and it would be strait-forward enough to just mimic the approach we're taking w/ string bundles.