Skip to content

Commit

Permalink
feat: add limit addon
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Mar 18, 2018
1 parent 4b99f7a commit 4b2ab42
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion addon/googleFont.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ exports.addon = function (renderer) {
};
} else {
renderer.googleFont = function (font, weights, subsets) {
renderer.raw = "@import url('" + createUrl(font, weights, subsets) + "');" + renderer.raw;
renderer.putRaw("@import url('" + createUrl(font, weights, subsets) + "');");
};
}
};
2 changes: 1 addition & 1 deletion addon/keyframes.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ exports.addon = function (renderer) {
if (renderer.client) {
renderer.ksh.appendChild(document.createTextNode(str));
} else {
renderer.raw += str;
renderer.putRaw(str);
}

return;
Expand Down
26 changes: 26 additions & 0 deletions addon/limit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

exports.addon = function (renderer, limit) {
limit = limit || 50000;

if (process.env.NODE_ENV !== 'production') {
require('./__dev__/warnOnMissingDependencies')('limit', renderer, ['putRaw']);
}

if (!renderer.client) {
var putRaw = renderer.putRaw;

renderer.putRaw = function (rawCssRule) {
if (renderer.raw.length + rawCssRule.length > limit) {
/* eslint-disable */
console.info('CSS was not injected, because it would go over ' + limit + ' byte limit.');
console.log(rawCssRule);
/* eslint-enable */

return;
}

putRaw(rawCssRule);
};
}
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nano-css",
"version": "1.2.0",
"version": "1.3.0",
"description": "Smallest 5th gen CSS-in-JS library",
"main": "index.js",
"unpkg": "dist/nano-css.umd.min.js",
Expand Down

0 comments on commit 4b2ab42

Please sign in to comment.