Skip to content

Instantly share code, notes, and snippets.

View jamsesso's full-sized avatar

Sam Jesso jamsesso

  • Fredericton, Canada
  • 22:23 (UTC -03:00)
View GitHub Profile
@jamsesso
jamsesso / services.js
Last active March 27, 2016 17:26
ES6 Directives in AngularJS - Registering services
import * as services from './module';
const serviceModule = angular.module('app.services', []);
// Automatically register each service.
Object.keys(services).forEach(key => {
if(!services[key].__service) {
console.warn(`Service ${key} is missing the @Service decorator.`);
return;
}
@jamsesso
jamsesso / decorators.js
Last active March 27, 2016 16:56
ES6 Directives in Angular - Decorators
function Service(name) {
return target => {
target.__service = { name };
return target;
}
}
function Controller(name, stateOpts) {
return target => {
target.__controller = { name, stateOpts }; // stateOpts get passed to $stateProvider during registration.
@jamsesso
jamsesso / directives.js
Created March 27, 2016 16:54
ES6 Directives in Angular - factoryize
import { Inject } from 'decorators';
function factoryize(directive) {
return directive.$inject
? Inject(...directive.$inject)((...dependencies) => new directive(...dependencies))
: () => new directive();
}
import { Inject, Directive } from 'decorators';
@Inject('$scope', '$compile')
@Directive('myDirective')
class MyDirective {
constructor($scope, $compile) {
// ...
}
}
@jamsesso
jamsesso / directives.js
Last active March 27, 2016 17:25
ES6 Directives in Angular - Directive registration
import { Inject } from 'decorators';
import * as directives from './module';
function factoryize(directive) {
return directive.$inject
? Inject(...directive.$inject)((...dependencies) => new directive(...dependencies))
: () => new directive();
}
const directivesModule = angular.module('app.directives', []);
@Service
public class BatchServiceImpl {
@Scheduled(cron = "your-cron-expression-here (example: */5 * * * * MON-FRI would execute on weekdays)")
public void sendReport() {
// ...
}
}
import React, { Component, PropTypes } from 'react'
import { render } from 'react-dom'
class Parent extends Component {
static childContextTypes = {
someContext1: PropTypes.object,
someContext2: PropTypes.object
}
render() {
import React, { Component } from 'react'
function withContext(key, type) {
return WrappedComponent => class ContextComponent extends Component {
static contextTypes = {
...WrappedComponent.contextTypes,
[key]: type
}
render() {
import React, { Component, PropTypes } from 'react'
import { render } from 'react-dom'
import withContext from './with-context'
class Parent extends Component {
static childContextTypes = {
someContext1: PropTypes.object,
someContext2: PropTypes.object
}
function thread(arg, ...funcs) {
return funcs.reduce((prev, func) => func(prev), arg)
}
export default thread