Individual imports
// Ember Data 2.3+
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import {belongsTo, hasMany} from 'ember-data/relationships';
// Ember (imports the whole thing)
import Ember from 'ember';
const {
computed,
computed: {
alias
}
} = Ember;
Individual imports
// lodash 3
import _groupBy from 'npm:lodash/collection/groupBy';
// lodash 4: no namespace
import _groupBy from 'npm:lodash/groupBy';
// lodash 4 server-side
// (but distro size doesn't matter)
const _groupBy = require('lodash/groupBy');
// lodash 4: can import a namespace (but don't)
import _collection from 'npm:lodash/collection';
Huge downside: no chaining
// Chaining
import _ from 'npm:lodash';
const result =
_(sourceData)
.groupBy('someField')
.map(someCallback)
.uniq()
.value();
// Using individual methods reverses order
// and ruins readability
import _groupBy from 'npm:lodash/groupBy';
import _map from 'npm:lodash/map';
import _uniq from 'npm:lodash/uniq';
const result =
_uniq(
_map(
_groupBy(sourceData, 'someField'),
someCallback
)
);
FP-style lodash funcitons
// Normal function
import _map from 'npm:lodash/map';
let result = _map(sourceData, callback);
// FP-style function
import _mapFP from 'npm:lodash/fp/map';
result = _mapFP(callback, sourceData); // Reverse order, no optional args
result = _mapFP(callback)(sourceData); // Currying!
No chaining solution: flow()
// Chaining
import _ from 'npm:lodash';
const result =
_(sourceData)
.groupBy('someField')
.map(someCallback)
.uniq()
.value();
// Chaining relpacement via flow()
import _groupByFP from 'npm:lodash/fp/groupBy';
import _mapFP from 'npm:lodash/fp/map';
import _uniq from 'npm:lodash/uniq';
import _flow from 'npm:lodash/flow';
let result =
_flow(
_groupByFP('someField'),
_mapFP(someCallback),
_uniq
)(data);
import chainy from 'exam-sim-ember/utils/chainy';
let result =
chainy(sourceData)(
_groupByFP('someField'),
_map(someCallback),
_uniq);