Skip to content

Fixed issue with redundant mounting/unmounting + better position check #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 9 additions & 4 deletions div-icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ export default class Divicon extends MapLayer {
}

updateLeafletElement(fromProps, toProps) {
if (toProps.position !== fromProps.position) {
// Even if we don't get a legnth of 2, this will work as the array will return undefined
const fromPosition = fromProps.position || []
const toPosition = toProps.position || []

if (toPosition[0] !== fromPosition[0] ||
toPosition[1] !== fromPosition[1]) {
this.leafletElement.setLatLng(toProps.position);
}
if (toProps.zIndexOffset !== fromProps.zIndexOffset) {
Expand All @@ -72,6 +77,7 @@ export default class Divicon extends MapLayer {

componentDidMount() {
super.componentDidMount();
this.ContextProvider = createContextProvider({...this.context, ...this.getChildContext()});
this.renderComponent();
}

Expand All @@ -81,12 +87,11 @@ export default class Divicon extends MapLayer {
}

renderComponent = () => {
const ContextProvider = createContextProvider({...this.context, ...this.getChildContext()});
const container = this.leafletElement._icon;
const component = (
<ContextProvider>
<this.ContextProvider>
{this.props.children}
</ContextProvider>
</this.ContextProvider>
);
if (container) {
render(
Expand Down
13 changes: 9 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ var Divicon = function (_MapLayer) {
_inherits(Divicon, _MapLayer);

function Divicon() {
var _ref;
var _ref,
_this3 = this;

var _temp, _this2, _ret;

Expand All @@ -81,10 +82,9 @@ var Divicon = function (_MapLayer) {
}

return _ret = (_temp = (_this2 = _possibleConstructorReturn(this, (_ref = Divicon.__proto__ || Object.getPrototypeOf(Divicon)).call.apply(_ref, [this].concat(args))), _this2), _this2.renderComponent = function () {
var ContextProvider = createContextProvider(_extends({}, _this2.context, _this2.getChildContext()));
var container = _this2.leafletElement._icon;
var component = _react2.default.createElement(
ContextProvider,
_this3.ContextProvider,
null,
_this2.props.children
);
Expand Down Expand Up @@ -118,7 +118,11 @@ var Divicon = function (_MapLayer) {
}, {
key: 'updateLeafletElement',
value: function updateLeafletElement(fromProps, toProps) {
if (toProps.position !== fromProps.position) {
// Even if we don't get a legnth of 2, this will work as the array will return undefined
var fromPosition = fromProps.position || [];
var toPosition = toProps.position || [];

if (toProps.position[0] !== fromProps.position[0] || toProps.position[1] !== fromProps.position[1]) {
this.leafletElement.setLatLng(toProps.position);
}
if (toProps.zIndexOffset !== fromProps.zIndexOffset) {
Expand All @@ -145,6 +149,7 @@ var Divicon = function (_MapLayer) {
key: 'componentDidMount',
value: function componentDidMount() {
_get(Divicon.prototype.__proto__ || Object.getPrototypeOf(Divicon.prototype), 'componentDidMount', this).call(this);
this.ContextProvider = createContextProvider(_extends({}, this.context, this.getChildContext()));
this.renderComponent();
}
}, {
Expand Down