Last active
May 28, 2019 17:14
-
-
Save sukima/89405129e337ecb8551a81b4be01a9e8 to your computer and use it in GitHub Desktop.
Each key example
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
import Component from '@ember/component'; | |
import { computed } from '@ember/object'; | |
export default Component.extend({ | |
tagName: 'span', | |
didInsertElement() { | |
this._super(...arguments); | |
this.logger.log(`${this.name} didInsertElement`, 'insert'); | |
}, | |
willDestroyElement() { | |
this._super(...arguments); | |
this.logger.log(`${this.name} willDestroyElement`, 'destroy'); | |
} | |
}); |
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
import Component from '@ember/component'; | |
function timeStamp() { | |
let now = new Date(); | |
let m = now.getMinutes(); | |
let s = now.getSeconds(); | |
let ms = now.getMilliseconds(); | |
return `${m}:${s}.${ms}`; | |
} | |
export default Component.extend({ | |
tagName: '', | |
init() { | |
this._super(...arguments); | |
this.set('logStack', []); | |
}, | |
actions: { | |
log(message, classname) { | |
this.logStack.pushObject({ message: `${timeStamp()}: ${message}`, classname }); | |
} | |
} | |
}); |
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
import Controller from '@ember/controller'; | |
import { computed } from '@ember/object'; | |
let uniqId = 1; | |
function uniqName(name) { | |
return `${name}-${uniqId++}`; | |
} | |
export default Controller.extend({ | |
testArray: computed('originalArray.[]', function() { | |
return this.originalArray.map((item) => { | |
return Object.assign({}, item); | |
}); | |
}), | |
init() { | |
this._super(...arguments); | |
this.set('originalArray', [ | |
{ name: uniqName('a'), value: 'A' }, | |
{ name: uniqName('b'), value: 'B' }, | |
{ name: uniqName('c'), value: 'B' } | |
]); | |
}, | |
actions: { | |
add(value) { | |
this.originalArray.pushObject({ name: uniqName(value.toLowerCase()), value }); | |
}, | |
remove(name) { | |
let obj = this.originalArray.findBy('name', name); | |
this.originalArray.removeObject(obj); | |
} | |
} | |
}); |
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
.columns { | |
display: flex; | |
} | |
.log-item { | |
padding: 0 5px; | |
margin: 5px 0; | |
} | |
.log-item.insert { | |
background-color: lightgreen; | |
} | |
.log-item.destroy { | |
background-color: red; | |
} | |
.data { | |
list-style: none; | |
padding: 0; | |
} | |
.data-item { | |
margin: 0; | |
padding: 0 5px; | |
} |
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
{ | |
"version": "0.15.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.4.3", | |
"ember-template-compiler": "3.4.3", | |
"ember-testing": "3.4.3" | |
}, | |
"addons": { | |
"ember-data": "3.4.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment