Skip to content

Instantly share code, notes, and snippets.

@floatdrop
Forked from azproduction/b_.with.jsx
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save floatdrop/c7fd22c42aa8348eb4a7 to your computer and use it in GitHub Desktop.
Save floatdrop/c7fd22c42aa8348eb4a7 to your computer and use it in GitHub Desktop.
var B = require('b_');
var Array_of = function (any) {
return Array.prototype.slice.call(any);
};
B.with = function () {
var b = this,
curriedArgs = Array_of(arguments);
return function () {
return b.apply(null, curriedArgs.concat(Array_of(arguments)));
};
};
var b = B.with('b-button');
var e = B.with('b-button', 'elem');
// After
function render() {
return (
<div className={b()}>
<span className={b('icon', {type: 'add'})}></span>
<span className={b('text')}></span>
</div>
<div className={b({size: 'small'})}>
<span className={b('icon', {type: 'add'})}></span>
<span className={b('text')}></span>
</div>
);
}
// Before
function render() {
return (
<div className={b('b-button')}>
<span className={b('b-button', 'icon', {type: 'add'})}></span>
<span className={b('b-button', 'text')}></span>
</div>
<div className={b('b-button', {size: 'small'})}>
<span className={b('b-button', 'icon', {type: 'add'})}></span>
<span className={b('b-button', 'text')}></span>
</div>
);
}
// Could be
function render() {
return (
<bbutton>
<span className="icon" type="add"></span>
<span className="text"></span>
</bbutton>
<bbutton size="small">
<span className="icon" type="add"></span>
<span className="text"></span>
</bbutton>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment