Skip to content

Instantly share code, notes, and snippets.

View arvidkahl's full-sized avatar
🏠
Working from home

Arvid Kahl arvidkahl

🏠
Working from home
View GitHub Profile
@arvidkahl
arvidkahl / jtw-chevrons.js
Created February 18, 2017 09:00
jtw-chevrons
// Modifying the tree-view-item component
// ...
data: function(){
return {
open: true
}
},
methods: {
isOpen: function(){
return this.isRootObject(this.data) || this.open;
@arvidkahl
arvidkahl / jtw-vti-component.css
Last active February 18, 2017 08:48
jtw-vti-component.js
// Add some CSS for indentation
.tree-view-item {
margin-left: 10px;
}
@arvidkahl
arvidkahl / jtv-transformation.js
Last active February 18, 2017 08:22
jtv-transformation.js
// ... inside the tree-view component
methods: {
// Transformer for the non-Collection types,
// like String, Integer of Float
transformValue: function(valueToTransform, keyForValue){
return {
key: keyForValue,
type: "value",
@arvidkahl
arvidkahl / jtv-empty-component.js
Last active February 18, 2017 07:21
jtv-empty-component.js
Vue.component("tree-view", Vue.extend({
name: "tree-view",
template: "<div>Tree View</div>",
props: ["data"],
methods: {},
computed: {}
}));
// To be used with <tree-view :data="sampleData"></tree-view>
@arvidkahl
arvidkahl / data.html
Created February 17, 2017 18:49
JSON Tree View Basic HTML
<div class="container" id="vue-root">
<div class="row">
<div class="col-xs-12">
<h1>A JSON Tree View Component in Vue.js</h1>
</div>
</div>
<div class="row">
<div class="col-xs-6">
<pre><code>{{formatJSON(sampleData)}}</code></pre>
@arvidkahl
arvidkahl / eventbus-advanced-events.js
Created February 12, 2017 08:18
eventbus-advanced-events.js
// Emit an Event from a Component using the internal Event Bus
let ComponentWithEventBus = Vue.extend({
mounted: function(){
this.$bus.$emit('status', 'Component mounted')
this.$bus.$on('something', ()=>{
console.log("Something happened");
});
}
});
@arvidkahl
arvidkahl / eventbus-advanced-prototype.js
Created February 12, 2017 08:14
eventbus-advanced-prototype.js
// Create a global Event Bus
var EventBus = new Vue()
// Add to Vue properties by exposing a getter for $bus
Object.defineProperties(Vue.prototype, {
$bus: {
get: function () {
return EventBus;
}
}
@arvidkahl
arvidkahl / components-eventbus.js
Created February 11, 2017 09:34
components-eventbus.js
// Two isolated components accessing the same global
let ComponentA = Vue.extend({
  created: function(){
  EventBus.$on(“thatEvent”, ()=>{
  console.log(“Event received”);
  })
  }
});
@arvidkahl
arvidkahl / eventbus.js
Last active February 11, 2017 09:32
eventbus.js
// A single, basic Vue.js instance
let EventBus = new Vue();
@arvidkahl
arvidkahl / count-dom-elements-on-page.js
Created January 27, 2016 17:48
Count DOM Element type occurrences on a page
[].map.call(document.all,function(el){return el.nodeName}).reduce(function(prev,curr){prev[curr]=(prev[curr]||0)+1;return prev},{})