once
There are times when you prefer a given functionality only happen once, similar to the way you'd use an onload event. This code provides you said functionality:
function once(fn, context) {
var result;
# If usb hdd is made sleeping using hdparm or unbind. The usb device still consumes about 1W. | |
# This power consumtpion could be spared removing whole usb hub from pci bus | |
# Make sleep using hdparm | |
########################################## | |
hdparm -y /dev/sdb | |
# Connect / disconnect usb device | |
########################################### |
var walked = []; | |
var searchHaystack = function(haystack, needle, path, exactEquals) { | |
//dumb truthiness handling | |
exactEquals = exactEquals ? true : false; | |
if(typeof haystack != "object") { | |
console.warn("non-object haystack at " + path.join(".")); | |
return [false, null]; |
private Repository getRepository() { | |
String domain = ((Unique) annotation).domain(); | |
try { | |
Repositories repositories = new Repositories(listableBeanFactory); | |
Class domainClass = Class.forName(domain); | |
Optional repo = repositories.getRepositoryFor(domainClass); | |
if (repo.isPresent()) { | |
return (Repository) repo.get(); | |
} else { | |
throw new RuntimeException("Repository for " + domain + " not found"); |
// get computed properties descriptors - eg: for clonning | |
const metal = Ember.__loader.require('ember-metal'); | |
EmberObject.eachComputedProperty(key => { | |
const descriptor = metal.descriptorFor(Model.prototype, key); | |
// console.log(descriptor._getter.toString()); | |
// now we can take descriptor._getter or descriptor._getter to create computed property on target object | |
}) |
// to import | |
const metal = Ember.__loader.require('ember-metal'); | |
// to review registry | |
const registry = Ember.__loader.registry | |
console.log(registry); |
//Usage of metas: http://emberjs.com/api/classes/Ember.ComputedProperty.html#method_meta | |
const o = Ember | |
.Object | |
.extend({ | |
prop: Ember.computed(function(key) { | |
console.log(this.constructor.metaForProperty(key)); | |
}).meta({key: 'value'}) | |
}).create(); |
/** | |
There is no support for pod based components in addons as of ember 2.9. Also as ember is moving to https://github.com/emberjs/rfcs/blob/master/text/0143-module-unification.md | |
pods are being discontinued (no longer supported). But for better organization of large in-repo addons pods are a must. | |
This gist provides solution how to use pods based components in in-repo addon. Even components.js based in pods of addon works problem is that template is not | |
being compiled. Following adjustments provides also compilation of template. Its only solution I found because of private | |
anonymous function in ember-cli which handles template compilation of addons. | |
To use pods in addon |
once
There are times when you prefer a given functionality only happen once, similar to the way you'd use an onload event. This code provides you said functionality:
function once(fn, context) {
var result;
// returns infos with model and parameters for each route | |
getRouterInfos: function() { | |
var router = this.get('router'); | |
var infos = router.router.currentHandlerInfos.slice(); | |
// normalize latest. because it is e.g. 'streams.index' | |
var latest = infos[infos.length-1]; | |
var names = latest.name.split('.'); | |
latest.name = names[names.length-1]; |
if (this.get('router.router.activeTransition.targetName') === 'credentials.signin') { | |
return Ember.RSVP.resolve(); | |
} |