-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 93399ed
Showing
18 changed files
with
3,220 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["latest", "react", "stage-1"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
end_of_line = lf | ||
insert_final_newline = true | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"env": { | ||
"es6": true | ||
}, | ||
"extends": [ | ||
"plugin:flowtype/recommended", | ||
"plugin:react/recommended", | ||
"prettier", | ||
"prettier/flowtype", | ||
"prettier/react" | ||
], | ||
"parser": "babel-eslint", | ||
"parserOptions": { | ||
"ecmaVersion": 2016, | ||
"jsx": true, | ||
"sourceType": "module" | ||
}, | ||
"plugins": [ | ||
"flowtype", | ||
"prettier", | ||
"react" | ||
], | ||
"rules": { | ||
"prettier/prettier": [ | ||
"error", | ||
{ | ||
"jsxBracketSameLine": true, | ||
"semi": false, | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[ignore] | ||
|
||
[include] | ||
|
||
[libs] | ||
|
||
[options] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2017 Paul Le Cam and contributors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.renderToJSON = exports.convertToObject = exports.convertChildren = exports.convertChild = undefined; | ||
|
||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
|
||
var _react = require('react'); | ||
|
||
var _react2 = _interopRequireDefault(_react); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
|
||
var convertChild = exports.convertChild = function convertChild(child) { | ||
if (child == null) { | ||
return; | ||
} | ||
if (typeof child === 'string') { | ||
return child; | ||
} | ||
if (child.type) { | ||
return convertToObject(child); | ||
} | ||
}; | ||
|
||
var convertChildren = exports.convertChildren = function convertChildren(children) { | ||
return Array.isArray(children) ? children.map(convertChild) : [convertChild(children)]; | ||
}; | ||
|
||
var convertToObject = function convertToObject(tree) { | ||
var type = void 0; | ||
if (typeof tree.type === 'string') { | ||
type = tree.type; | ||
} else if (tree.type.displayName) { | ||
type = tree.type.displayName; | ||
} else if (tree.type.name) { | ||
type = tree.type.name; | ||
} | ||
|
||
var _tree$props = tree.props, | ||
children = _tree$props.children, | ||
props = _objectWithoutProperties(_tree$props, ['children']); | ||
|
||
return { | ||
type: type, | ||
props: _extends({}, props, { | ||
children: convertChildren(children) | ||
}) | ||
}; | ||
}; | ||
|
||
exports.convertToObject = convertToObject; | ||
var renderToJSON = exports.renderToJSON = function renderToJSON(tree, space) { | ||
return JSON.stringify(convertToObject(tree), null, space); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
|
||
var _converter = require('./converter'); | ||
|
||
Object.defineProperty(exports, 'convertToObject', { | ||
enumerable: true, | ||
get: function get() { | ||
return _converter.convertToObject; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'renderToJSON', { | ||
enumerable: true, | ||
get: function get() { | ||
return _converter.renderToJSON; | ||
} | ||
}); | ||
|
||
var _renderer = require('./renderer'); | ||
|
||
Object.defineProperty(exports, 'renderFromObject', { | ||
enumerable: true, | ||
get: function get() { | ||
return _renderer.renderFromObject; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'Renderer', { | ||
enumerable: true, | ||
get: function get() { | ||
return _renderer.Renderer; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.Renderer = exports.renderFromObject = undefined; | ||
|
||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
|
||
var _react = require('react'); | ||
|
||
var _react2 = _interopRequireDefault(_react); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
|
||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
|
||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
|
||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
|
||
var Fallback = function Fallback() { | ||
return null; | ||
}; | ||
|
||
var renderFromObject = function renderFromObject(tree, params) { | ||
var components = params.components || {}; | ||
var fallback = params.fallback || Fallback; | ||
|
||
var createChild = function createChild(c) { | ||
if (c == null) { | ||
return null; | ||
} | ||
if (typeof c === 'string') { | ||
return c; | ||
} | ||
if (c.type) { | ||
return createComponent(c); | ||
} | ||
return null; | ||
}; | ||
|
||
var createComponent = function createComponent(converted) { | ||
var component = components[converted.type] || fallback; | ||
|
||
var _converted$props = converted.props, | ||
children = _converted$props.children, | ||
props = _objectWithoutProperties(_converted$props, ['children']); | ||
|
||
if (children) props.children = children.map(createChild); | ||
return (0, _react.createElement)(component, props); | ||
}; | ||
|
||
return createComponent(tree); | ||
}; | ||
|
||
exports.renderFromObject = renderFromObject; | ||
|
||
var Renderer = exports.Renderer = function (_Component) { | ||
_inherits(Renderer, _Component); | ||
|
||
function Renderer() { | ||
_classCallCheck(this, Renderer); | ||
|
||
return _possibleConstructorReturn(this, (Renderer.__proto__ || Object.getPrototypeOf(Renderer)).apply(this, arguments)); | ||
} | ||
|
||
_createClass(Renderer, [{ | ||
key: 'render', | ||
value: function render() { | ||
var _props = this.props, | ||
json = _props.json, | ||
tree = _props.tree, | ||
params = _objectWithoutProperties(_props, ['json', 'tree']); | ||
|
||
var obj = void 0; | ||
if (tree) obj = tree;else if (json) obj = JSON.parse(json); | ||
|
||
return obj ? renderFromObject(obj, params) : null; | ||
} | ||
}]); | ||
|
||
return Renderer; | ||
}(_react.Component); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
'use strict'; | ||
|
||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
|
||
var _react = require('react'); | ||
|
||
var _react2 = _interopRequireDefault(_react); | ||
|
||
var _index = require('./index'); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
|
||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
|
||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
|
||
var Empty = function Empty() { | ||
return null; | ||
}; | ||
var View = function View(_ref) { | ||
var children = _ref.children; | ||
return children; | ||
}; | ||
var Hello = function Hello(_ref2) { | ||
var name = _ref2.name; | ||
return 'Hello ' + name; | ||
}; | ||
var Placeholder = 'Placeholder'; | ||
|
||
var ClassComponent = function (_React$Component) { | ||
_inherits(ClassComponent, _React$Component); | ||
|
||
function ClassComponent() { | ||
_classCallCheck(this, ClassComponent); | ||
|
||
return _possibleConstructorReturn(this, (ClassComponent.__proto__ || Object.getPrototypeOf(ClassComponent)).apply(this, arguments)); | ||
} | ||
|
||
_createClass(ClassComponent, [{ | ||
key: 'render', | ||
value: function render() { | ||
return this.props.children; | ||
} | ||
}]); | ||
|
||
return ClassComponent; | ||
}(_react2.default.Component); | ||
|
||
var tree = _react2.default.createElement( | ||
ClassComponent, | ||
null, | ||
_react2.default.createElement( | ||
View, | ||
{ style: 'primary' }, | ||
_react2.default.createElement(Empty, null), | ||
_react2.default.createElement(Hello, { name: 'Bob' }), | ||
_react2.default.createElement( | ||
View, | ||
null, | ||
_react2.default.createElement(Placeholder, null) | ||
) | ||
) | ||
); | ||
|
||
var JSONRes = (0, _index.renderToJSON)(tree); | ||
|
||
var objectRes = JSON.parse(JSONRes); | ||
|
||
var components = { | ||
ClassComponent: function ClassComponent(_ref3) { | ||
var children = _ref3.children; | ||
return children; | ||
}, | ||
Empty: function Empty() { | ||
return null; | ||
}, | ||
View: function View(_ref4) { | ||
var children = _ref4.children; | ||
return children; | ||
}, | ||
Hello: function Hello(_ref5) { | ||
var name = _ref5.name; | ||
return 'Hello ' + name; | ||
}, | ||
Placeholder: function Placeholder() { | ||
return 'Placeholder text'; | ||
} | ||
}; | ||
|
||
var res = (0, _index.renderFromObject)(objectRes, { components: components }); | ||
|
||
console.log('res', res); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
'use strict'; |
Oops, something went wrong.