Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

Commit

Permalink
Add createContext (#529)
Browse files Browse the repository at this point in the history
* add and export preact-context (createContext)

* run linter

* unmark preact-context as external

The rationale behind marking dependencies as external is because
they're likely to already be installe in the client projects and
flat bundling them is unnecessary extra code. However preact-context
is very new and people are less likely to be using it so we'll bundle it.
  • Loading branch information
quantizor authored and developit committed Jun 14, 2019
1 parent a3e44f7 commit 9a58b98
Show file tree
Hide file tree
Showing 14 changed files with 221 additions and 190 deletions.
8 changes: 4 additions & 4 deletions lib/ReactFragment.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
var preact = require('preact-compat');

exports.create = function(obj) {
exports.create = function (obj) {
var children = [];
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
var child = [].concat(obj[key]);
for (var i=0; i<child.length; i++) {
for (var i = 0; i < child.length; i++) {
var c = child[i];
// if unkeyed, clone attrs and inject key
if (preact.isValidElement(c) && !(c.attributes && c.attributes.key)) {
var a = {};
if (c.attributes) for (var j in c.attributes) a[j] = c.attributes[j];
a.key = key+'.'+i;
a.key = key + '.' + i;
c = preact.createElement(c.nodeName, a, c.children);
}
if (c!=null) children.push(c);
if (c != null) children.push(c);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/ReactPerf.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function noop(){}
function noop() { }

'getLastMeasurements getExclusive getInclusive getWasted getOperations printExclusive printInclusive printWasted printOperations start stop isRunning'
.split(' ').forEach(function(key) {
module.exports[key]=noop;
.split(' ').forEach(function (key) {
module.exports[key] = noop;
});
6 changes: 3 additions & 3 deletions lib/ReactTransitionEvents.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var supported, prefix;

if (typeof document!=='undefined' && document.createElement) {
if (typeof document !== 'undefined' && document.createElement) {
var d = document.createElement('div');
for (var i in d.style) {
var m = i.match(/^(moz|webkit|ms|)(transition|animation)$/i);
Expand All @@ -10,8 +10,8 @@ if (typeof document!=='undefined' && document.createElement) {
}

function each(node, fn, listener, prefix) {
node[fn]((prefix || '')+'TransitionEnd', listener);
node[fn]((prefix || '')+'AnimationEnd', listener);
node[fn]((prefix || '') + 'TransitionEnd', listener);
node[fn]((prefix || '') + 'AnimationEnd', listener);
if (prefix) each(node, fn, listener);
}

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@
},
"dependencies": {
"immutability-helper": "^2.7.1",
"preact-context": "^1.1.3",
"preact-render-to-string": "^3.8.2",
"preact-transition-group": "^1.1.1",
"prop-types": "^15.6.2",
"standalone-react-addons-pure-render-mixin": "^0.1.1"
}
}
}
15 changes: 10 additions & 5 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ import commonjs from 'rollup-plugin-commonjs';

let pkg = JSON.parse(fs.readFileSync('./package.json'));

let external = Object.keys(pkg.peerDependencies || {}).concat(Object.keys(pkg.dependencies || {}));
/**
* The rationale behind marking dependencies as external is because they're likely to already be installed
* in the client projects and flat bundling them is unnecessary extra code. However preact-context is very
* new and people are less likely to be using it so we'll bundle it.
*/
let external = Object.keys(pkg.peerDependencies || {}).concat(Object.keys(pkg.dependencies || {})).filter(x => x !== 'preact-context');

let format = process.env.FORMAT==='es' ? 'es' : 'umd';
let format = process.env.FORMAT === 'es' ? 'es' : 'umd';

export default {
input: 'src/index.js',
output: {
name: pkg.amdName,
exports: format==='es' ? null : 'default',
file: format==='es' ? pkg.module : pkg.main,
exports: format === 'es' ? null : 'default',
file: format === 'es' ? pkg.module : pkg.main,
format,
globals: {
'preact': 'preact',
Expand All @@ -26,7 +31,7 @@ export default {
external,
strict: false,
plugins: [
format==='umd' && memory({
format === 'umd' && memory({
path: 'src/index.js',
contents: "export { default } from './index';"
}),
Expand Down
Loading

0 comments on commit 9a58b98

Please sign in to comment.