react-cosmos
Advanced tools
Comparing version 1.0.0-beta.3 to 1.0.0-beta.4
@@ -44,2 +44,23 @@ 'use strict'; | ||
*/ | ||
var isReactClass = function isReactClass(component) { | ||
return typeof component === 'string' || typeof component === 'function'; | ||
}; | ||
var getFixturesForComponent = function getFixturesForComponent(allFixtures, componentName) { | ||
var isFixtureOfComponent = new RegExp(componentName + '/([^/]+)$'); | ||
var fixtures = {}; | ||
Object.keys(allFixtures).forEach(function (fixturePath) { | ||
var match = fixturePath.match(isFixtureOfComponent); | ||
if (match) { | ||
var fixture = allFixtures[fixturePath]; | ||
// eslint-disable-next-line no-underscore-dangle | ||
fixtures[match[1]] = fixture.__esModule ? fixture.default : fixture; | ||
} | ||
}); | ||
return fixtures; | ||
}; | ||
module.exports = function (components, fixtures) { | ||
@@ -54,2 +75,3 @@ var componentFixtures = {}; | ||
// It looks like to be a "standard": https://github.com/esnext/es6-module-transpiler/issues/86 **for now**. | ||
// eslint-disable-next-line no-underscore-dangle | ||
if (component.__esModule) { | ||
@@ -78,20 +100,2 @@ var parts = componentPath.split('/'); | ||
return componentFixtures; | ||
}; | ||
var isReactClass = function isReactClass(component) { | ||
return typeof component === 'string' || typeof component === 'function'; | ||
}; | ||
var getFixturesForComponent = function getFixturesForComponent(allFixtures, componentName) { | ||
var isFixtureOfComponent = new RegExp(componentName + '/([^/]+)$'), | ||
fixtures = {}; | ||
Object.keys(allFixtures).forEach(function (fixturePath) { | ||
var match = fixturePath.match(isFixtureOfComponent); | ||
if (match) { | ||
fixtures[match[1]] = allFixtures[fixturePath]; | ||
} | ||
}); | ||
return fixtures; | ||
}; |
'use strict'; | ||
var ReactQuerystringRouter = require('react-querystring-router'), | ||
ComponentPlayground = require('react-component-playground'), | ||
getComponentFixtures = require('./get-component-fixtures.js'); | ||
var _reactQuerystringRouter = require('react-querystring-router'); | ||
var _reactQuerystringRouter2 = _interopRequireDefault(_reactQuerystringRouter); | ||
var _reactComponentPlayground = require('react-component-playground'); | ||
var _reactComponentPlayground2 = _interopRequireDefault(_reactComponentPlayground); | ||
var _getComponentFixtures = require('./get-component-fixtures'); | ||
var _getComponentFixtures2 = _interopRequireDefault(_getComponentFixtures); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var getTitleForFixture = function getTitleForFixture(params) { | ||
@@ -16,12 +26,16 @@ var title = 'React Cosmos'; | ||
return title; | ||
}; | ||
}; /* eslint-env browser */ | ||
module.exports = function (components, fixtures) { | ||
return new ReactQuerystringRouter.Router({ | ||
module.exports = function (_ref) { | ||
var proxies = _ref.proxies; | ||
var components = _ref.components; | ||
var fixtures = _ref.fixtures; | ||
return new _reactQuerystringRouter2.default.Router({ | ||
container: document.body.appendChild(document.createElement('div')), | ||
defaultProps: { | ||
components: getComponentFixtures(components, fixtures) | ||
proxies: proxies, | ||
components: (0, _getComponentFixtures2.default)(components, fixtures) | ||
}, | ||
getComponentClass: function getComponentClass() { | ||
return ComponentPlayground; | ||
return _reactComponentPlayground2.default; | ||
}, | ||
@@ -28,0 +42,0 @@ onChange: function onChange(params) { |
{ | ||
"name": "react-cosmos", | ||
"version": "1.0.0-beta.3", | ||
"version": "1.0.0-beta.4", | ||
"description": "The glue between the React Cosmos modules", | ||
@@ -9,5 +9,5 @@ "repository": "https://github.com/skidding/react-cosmos/tree/master/packages/react-cosmos", | ||
"dependencies": { | ||
"react-component-playground": "^1.0.0-beta.3", | ||
"react-querystring-router": "^1.0.0-beta.2" | ||
"react-component-playground": "^1.0.0-beta.4", | ||
"react-querystring-router": "^1.0.0-beta.4" | ||
} | ||
} |
@@ -42,7 +42,27 @@ /** | ||
*/ | ||
module.exports = function(components, fixtures) { | ||
var componentFixtures = {}; | ||
const isReactClass = (component) => | ||
typeof component === 'string' || typeof component === 'function'; | ||
const getFixturesForComponent = (allFixtures, componentName) => { | ||
const isFixtureOfComponent = new RegExp(`${componentName}/([^/]+)$`); | ||
const fixtures = {}; | ||
Object.keys(allFixtures).forEach((fixturePath) => { | ||
const match = fixturePath.match(isFixtureOfComponent); | ||
if (match) { | ||
const fixture = allFixtures[fixturePath]; | ||
// eslint-disable-next-line no-underscore-dangle | ||
fixtures[match[1]] = fixture.__esModule ? fixture.default : fixture; | ||
} | ||
}); | ||
return fixtures; | ||
}; | ||
module.exports = (components, fixtures) => { | ||
const componentFixtures = {}; | ||
Object.keys(components).forEach((componentPath) => { | ||
var component = components[componentPath]; | ||
let component = components[componentPath]; | ||
@@ -52,5 +72,6 @@ // This is an implementation detail of Babel: | ||
// It looks like to be a "standard": https://github.com/esnext/es6-module-transpiler/issues/86 **for now**. | ||
// eslint-disable-next-line no-underscore-dangle | ||
if (component.__esModule) { | ||
var parts = componentPath.split('/'); | ||
var componentName = parts[parts.length - 1]; | ||
const parts = componentPath.split('/'); | ||
const componentName = parts[parts.length - 1]; | ||
component = component[componentName] || component.default; | ||
@@ -66,3 +87,3 @@ } | ||
class: component, | ||
fixtures: getFixturesForComponent(fixtures, componentPath) | ||
fixtures: getFixturesForComponent(fixtures, componentPath), | ||
}; | ||
@@ -78,19 +99,1 @@ | ||
}; | ||
var isReactClass = function(component) { | ||
return typeof component === 'string' || typeof component === 'function'; | ||
} | ||
var getFixturesForComponent = function(allFixtures, componentName) { | ||
var isFixtureOfComponent = new RegExp(componentName + '/([^/]+)$'), | ||
fixtures = {}; | ||
Object.keys(allFixtures).forEach(function(fixturePath) { | ||
var match = fixturePath.match(isFixtureOfComponent); | ||
if (match) { | ||
fixtures[match[1]] = allFixtures[fixturePath]; | ||
} | ||
}); | ||
return fixtures; | ||
}; |
@@ -1,11 +0,13 @@ | ||
var ReactQuerystringRouter = require('react-querystring-router'), | ||
ComponentPlayground = require('react-component-playground'), | ||
getComponentFixtures = require('./get-component-fixtures.js'); | ||
/* eslint-env browser */ | ||
var getTitleForFixture = function(params) { | ||
var title = 'React Cosmos'; | ||
import ReactQuerystringRouter from 'react-querystring-router'; | ||
import ComponentPlayground from 'react-component-playground'; | ||
import getComponentFixtures from './get-component-fixtures'; | ||
const getTitleForFixture = (params) => { | ||
let title = 'React Cosmos'; | ||
// Set document title to the name of the selected fixture | ||
if (params.component && params.fixture) { | ||
title = params.component + ':' + params.fixture + ' – ' + title; | ||
title = `${params.component}:${params.fixture} – ${title}`; | ||
} | ||
@@ -16,14 +18,17 @@ | ||
module.exports = (components, fixtures) => | ||
module.exports = ({ | ||
proxies, | ||
components, | ||
fixtures, | ||
}) => | ||
new ReactQuerystringRouter.Router({ | ||
container: document.body.appendChild(document.createElement('div')), | ||
defaultProps: { | ||
components: getComponentFixtures(components, fixtures) | ||
proxies, | ||
components: getComponentFixtures(components, fixtures), | ||
}, | ||
getComponentClass: function() { | ||
return ComponentPlayground; | ||
getComponentClass: () => ComponentPlayground, | ||
onChange: (params) => { | ||
document.title = getTitleForFixture(params); | ||
}, | ||
onChange: function(params) { | ||
document.title = getTitleForFixture(params); | ||
} | ||
}); |
8798
230