Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e0e9b2b
Prevent skip change event in store when it occurs between render and …
davidshimjs Nov 16, 2016
fdaec5c
Merge remote-tracking branch 'upstream/master'
senxation Nov 1, 2017
d476120
this.setState() will only call when the component is mounted. (in alt…
senxation Nov 1, 2017
b9c8dfe
Update states when changed store values before binding listeners
davidshimjs Nov 1, 2017
8d4257e
Fix tests
davidshimjs Nov 1, 2017
e9981fb
Fix missed module
davidshimjs Nov 1, 2017
5071efc
Don't use props on Native DOM Elements. Fix tests
davidshimjs Nov 1, 2017
23c5472
Supports React v16
davidshimjs Nov 1, 2017
0ecbaba
Updates babel and presets
davidshimjs Nov 1, 2017
544fd76
Define preset
davidshimjs Nov 1, 2017
6c7851b
Moves packages for build
davidshimjs Nov 1, 2017
238341a
Add prepublish script
davidshimjs Nov 1, 2017
0cdf76c
change script name
davidshimjs Nov 1, 2017
f5aab13
Change method to assign state value
davidshimjs Nov 1, 2017
58e720e
Remove npmignore file
davidshimjs Nov 3, 2017
6afe557
preinstall로 변경
davidshimjs Nov 3, 2017
2d7a6a3
Add prepublish step
davidshimjs Nov 11, 2017
f3cdab8
Add prepare hook
davidshimjs Jan 7, 2018
8d63f27
Merge branch 'master' of github.com:hogangnono/container
davidshimjs Jan 7, 2018
c70d106
change hook
davidshimjs Jan 7, 2018
a7971b7
prepare 추가
davidshimjs Jan 9, 2018
0f034aa
Uses React Fragment
davidshimjs Jan 23, 2018
699392b
Do not use cloneElement
davidshimjs Jan 24, 2018
32bc0e3
Fix bugs
davidshimjs Jan 24, 2018
1d86cc3
Revert "Fix bugs"
davidshimjs Jan 24, 2018
6f6a91a
Revert Changes
davidshimjs Jan 24, 2018
615b1b1
Fix package.json to publish npm@hogangnono
davidshimjs Sep 8, 2019
57758ea
Add prepublishOnly event
davidshimjs Sep 9, 2019
a7391e0
chore: @hogangnono/alt-container@1.1.2
zigbang-rad May 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["react", "es2015", "stage-2"]
}
1 change: 0 additions & 1 deletion .npmignore

This file was deleted.

35 changes: 23 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"name": "alt-container",
"version": "1.1.1",
"name": "@hogangnono/alt-container",
"version": "1.1.2",
"description": "A flux container for alt",
"main": "lib/AltContainer.js",
"scripts": {
"clean": "rimraf lib && rimraf utils",
"build": "babel src --out-dir lib --stage 0",
"prepublishOnly": "npm run build",
"test": "npm run clean && npm run build && mocha -u exports -R nyan --require ./test/babel test"
},
"repository": {
"type": "git",
"url": "git@github.com:altjs/container.git"
"url": "git@github.com:hogangnono/container.git"
},
"keywords": [
"altcontainer",
Expand All @@ -22,28 +23,38 @@
"flux",
"react"
],
"author": "Josh Perez <josh@goatslacker.com>",
"author": "hogangnono",
"license": "MIT",
"bugs": {
"url": "https://github.com/altjs/container/issues"
"url": "https://github.com/hogangnono/container/issues"
},
"homepage": "https://github.com/altjs/container",
"homepage": "https://github.com/hogangnono/container",
"dependencies": {
"babel-cli": "^6.26.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"create-react-class": "^15.6.2",
"object.assign": "^4.0.1",
"prop-types": "^15.5.10"
"prop-types": "^15.5.10",
"underscore": "^1.8.3"
},
"devDependencies": {
"alt": "0.17.4",
"alt-utils": "1.0.0",
"babel": "5.8.23",
"babel-core": "5.8.25",
"babel-core": "^6.26.0",
"chai": "3.3.0",
"jsdom": "6.5.1",
"mocha": "2.3.3",
"react": "0.14.0",
"react-addons-test-utils": "0.14.0",
"react-dom": "0.14.0",
"react": "^16.2.0",
"react-addons-test-utils": "^15.6.2",
"react-dom": "^16.2.0",
"rimraf": "2.4.3",
"sinon": "1.17.1"
},
"publishConfig": {
"registry": "https://npm.housefeed.com"
}
}
42 changes: 31 additions & 11 deletions src/AltContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
*/
import React from 'react'
import PropTypes from 'prop-types';
import assign from 'object.assign'
import assign from 'object.assign';
import _ from 'underscore';

const id = it => it
const getStateFromStore = (store, props) => {
Expand Down Expand Up @@ -117,11 +118,11 @@ const getStateFromStores = (props) => {
// what about propTypes?
class AltContainer extends React.Component {
static contextTypes = {
flux: PropTypes.object,
flux: PropTypes.object
}

static childContextTypes = {
flux: PropTypes.object,
flux: PropTypes.object
}

getChildContext() {
Expand Down Expand Up @@ -153,6 +154,13 @@ class AltContainer extends React.Component {
componentDidMount() {
this._registerStores(this.props)
if (this.props.onMount) this.props.onMount(this.props, this.context)

const nextState = reduceState(this.props);

// Update states when changed before binding listeners
if (!_.isEqual(this.state, nextState)) {
this.setState(nextState);
}
}

componentWillUnmount() {
Expand Down Expand Up @@ -224,18 +232,30 @@ class AltContainer extends React.Component {

// Does not wrap child in a div if we don't have to.
if (Array.isArray(children)) {
return React.createElement(Node, null, children.map((child, i) => {
return React.cloneElement(child, assign(
{ key: i },
this.getProps()
))
}))
return (
<React.Fragment>
{children.map((child, i) => {
if (React.isValidElement(child) && typeof child.type === 'string') {
return React.cloneElement(child, { key: i });
}

return React.cloneElement(child, assign(
{ key: i },
this.getProps()
));
})}
</React.Fragment>
);
} else if (children) {
return React.cloneElement(children, this.getProps())
if (React.isValidElement(children) && typeof children.type === 'string') {
return children;
} else {
return React.cloneElement(children, this.getProps())
}
} else {
return React.createElement(Node, this.getProps())
}
}
}

export default AltContainer
export default AltContainer;
3 changes: 2 additions & 1 deletion src/AltContainerLegacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@
import React from 'react'
import mixinContainer from './mixinContainer'
import assign from 'object.assign'
import createReactClass from 'create-react-class';

const AltContainer = React.createClass(assign({
const AltContainer = createReactClass(assign({
displayName: 'AltContainer',

render() {
Expand Down
3 changes: 2 additions & 1 deletion src/AltNativeContainerLegacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import React from 'react-native'
import mixinContainer from './mixinContainer'
import assign from 'object.assign'
import createReactClass from 'create-react-class';

const AltNativeContainer = React.createClass(assign({
const AltNativeContainer = createReactClass(assign({
displayName: 'AltNativeContainer',

render() {
Expand Down
35 changes: 28 additions & 7 deletions src/mixinContainer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*eslint-disable*/
import assign from 'object.assign'
import PropTypes from 'prop-types';
import _ from 'underscore';

const id = it => it

Expand Down Expand Up @@ -55,6 +56,13 @@ const mixinContainer = (React) => {
componentDidMount() {
this.registerStores(this.props)
if (this.props.onMount) this.props.onMount(this.props, this.context)

const nextState = reduceState(this.props);

// Update states when changed before binding listeners
if (!_.isEqual(this.state, nextState)) {
this.setState(nextState);
}
},

componentWillUnmount() {
Expand Down Expand Up @@ -160,6 +168,7 @@ const mixinContainer = (React) => {

altRender(Node) {
var children = this.props.children

// Custom rendering function
if (typeof this.props.render === 'function') {
return this.props.render(this.getProps())
Expand All @@ -169,14 +178,26 @@ const mixinContainer = (React) => {

// Does not wrap child in a div if we don't have to.
if (Array.isArray(children)) {
return React.createElement(Node, null, children.map((child, i) => {
return cloneElement(child, assign(
{ key: i },
this.getProps()
))
}, this))
return (
<React.Fragment>
{children.map((child, i) => {
if (React.isValidElement(child) && typeof child.type === 'string') {
return React.cloneElement(child, { key: i });
}

return cloneElement(child, assign(
{ key: i },
this.getProps()
));
})}
</React.Fragment>
);
} else if (children) {
return cloneElement(children, this.getProps())
if (React.isValidElement(children) && typeof children.type === 'string') {
return children;
} else {
return cloneElement(children, this.getProps())
}
} else {
return React.createElement(Node, this.getProps())
}
Expand Down
Loading