Skip to content

Instantly share code, notes, and snippets.

View giuseppeg's full-sized avatar
🌊
All is well.

Giuseppe giuseppeg

🌊
All is well.
View GitHub Profile
@giuseppeg
giuseppeg / flight-collections.js
Last active August 29, 2015 13:57
a FlightJS mixin to teardown a group of components
define(function (require) {
var registry = require('flight/lib/registry');
return withTeardownColletion;
function withTeardownCollection() {
this.before('teardown', function () {
if (typeof this.attr.collectionName == 'string') {
Object.keys(registry.allInstances).forEach(function (instanceKey) {
this.off = function() {
var $element, type, callback;
var lastIndex = arguments.length - 1;
var instanceInfo,
origTypeRegex = '^(type)(?:\.(.+)|)$';
if (typeof arguments[lastIndex] == 'function') {
callback = arguments[lastIndex];
lastIndex -= 1;
}
@giuseppeg
giuseppeg / test-main.js
Created August 6, 2014 14:15
flight test core path
'use strict';
var tests = Object.keys(window.__karma__.files).filter(function (file) {
return (/\.spec\.js$/.test(file));
});
requirejs.config({
// Karma serves files from '/base'
baseUrl: '/base/app/bower_components',
@giuseppeg
giuseppeg / flight-unbind-proxied-events.js
Last active August 29, 2015 14:05
unbind proxied event in FlightJS - patch idea
this.off = function() {
var $element, type, proxiedTo, callback;
var lastIndex = arguments.length - 1, origin = arguments[lastIndex];
if (typeof origin == 'function') {
callback = origin;
arguments[lastIndex] = undefined;
}
if (lastIndex == 1) {
// a.js
require(["b"], function(b) {
jsResult.innerHTML += "2 "
require(["c"], function() {
jsResult.innerHTML += "4 "
});
});
// b.js
@giuseppeg
giuseppeg / app-structure.md
Last active August 29, 2015 14:10
app front-end structure

Components (or modules) talk to each other via events.

  • vendor [3rd party scripts, this could as well be bower_components if you use bower]
  • core [app core functionalities/utilities]
  • component
    • component1
      • index.js [the actual js component]
      • spec.js [tests]
      • style.css [component styles]
  • index.partial.template
@giuseppeg
giuseppeg / SassMeister-input.scss
Created March 12, 2015 00:48
Generated by SassMeister.com.
// ----
// Sass (v3.4.12)
// Compass (v1.0.3)
// ----
/**
experiment: responsive (framework) all teh things
Usage
<div class="arrange" data-responsive-medium="block width red">test</div>
@giuseppeg
giuseppeg / component.js
Last active August 29, 2015 14:20
contextualize component
<div class="Header">
render_component('Button', {
href: '/blog'
},
[ /* contextual styles (array of utility classes) */
'u-size-1',
'u-space-2-top'
]
)
</div>
@giuseppeg
giuseppeg / SassMeister-input.scss
Created June 2, 2015 19:42
Generated by SassMeister.com.
// ----
// libsass (v3.2.4)
// ----
.test-support {
@each $fn in (get-color, to-hex) {
@if (not function-exists($fn)) {
@warn "#{$fn} doesn't exists or is not supported";
}
}
@giuseppeg
giuseppeg / contextualized-components.html
Last active August 29, 2015 14:22
using custom html attributes to contextualize components
<!--
Components are independent from each other.
They have no margin or position.
Components internal sizes are in ems.
https://gist.github.com/giuseppeg/0c3509803f8b14fa785a
(I am also trying to figure out if default line-height set to 1 is a good or bad thing
and if it helps with v-align stuff)
Component internals are styled with modifiers when necessary.
At rendering time components are contextualized with custom attrs.