@planet/maps
Advanced tools
Comparing version
/** | ||
* The constants below represent the primitive element types handled by the renderer. | ||
*/ | ||
export const MAP = 'map'; | ||
export const VIEW = 'view'; | ||
@@ -5,0 +6,0 @@ export const OVERLAY = 'overlay'; |
@@ -13,2 +13,3 @@ import BaseLayer from 'ol/layer/Base.js'; | ||
DefaultEventPriority, | ||
NoEventPriority, | ||
} from 'react-reconciler/constants.js'; | ||
@@ -45,16 +46,48 @@ import { | ||
export function updateInstanceFromProps(instance, props, oldProps = {}) { | ||
for (const key in props) { | ||
/** | ||
* @param {Array} a1 An array. | ||
* @param {Array} a2 An array. | ||
* @return {boolean} All elements in the array are the same; | ||
*/ | ||
function arrayEquals(a1, a2) { | ||
if (!a1 || !a2) { | ||
return false; | ||
} | ||
const len1 = a1.length; | ||
const len2 = a2.length; | ||
if (len1 !== len2) { | ||
return false; | ||
} | ||
for (let i = 0; i < len1; i += 1) { | ||
const v1 = a1[i]; | ||
const v2 = a2[i]; | ||
if (v1 !== v2) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
export function updateInstanceFromProps(instance, type, oldProps, newProps) { | ||
for (const key in newProps) { | ||
if (reservedProps[key]) { | ||
continue; | ||
} | ||
const newValue = newProps[key]; | ||
const oldValue = oldProps[key]; | ||
if (oldValue === newValue) { | ||
continue; | ||
} | ||
if (listenerRegex.test(key)) { | ||
const listener = props[key]; | ||
const type = key | ||
const listener = newProps[key]; | ||
const eventType = key | ||
.replace(listenerColonRegex, 'onChange:') | ||
.replace(listenerRegex, '$1') | ||
.toLowerCase(); | ||
instance.on(type, listener); | ||
if (oldProps[key]) { | ||
instance.un(type, oldProps[key]); | ||
instance.on(eventType, listener); | ||
const oldListener = oldProps[key]; | ||
if (oldListener) { | ||
instance.un(eventType, oldListener); | ||
if (instance.changed) { | ||
@@ -67,5 +100,9 @@ instance.changed(); | ||
if (key === 'center' && arrayEquals(newValue, oldValue)) { | ||
continue; | ||
} | ||
const setter = setterName(key); | ||
if (typeof instance[setter] === 'function') { | ||
instance[setter](props[key]); | ||
instance[setter](newValue); | ||
continue; | ||
@@ -77,3 +114,3 @@ } | ||
instance.clear(true); | ||
instance.addFeatures(props[key]); | ||
instance.addFeatures(newValue); | ||
continue; | ||
@@ -87,3 +124,3 @@ } | ||
instance.getInteractions().clear(); | ||
props[key].forEach(interaction => instance.addInteraction(interaction)); | ||
newValue.forEach(interaction => instance.addInteraction(interaction)); | ||
continue; | ||
@@ -93,3 +130,3 @@ } | ||
instance.getControls().clear(); | ||
props[key].forEach(control => instance.addControl(control)); | ||
newValue.forEach(control => instance.addControl(control)); | ||
continue; | ||
@@ -111,3 +148,3 @@ } | ||
const instance = new Constructor(props.options || {}); | ||
updateInstanceFromProps(instance, props); | ||
updateInstanceFromProps(instance, type, {}, props); | ||
return instance; | ||
@@ -177,4 +214,4 @@ } | ||
function commitUpdate(instance, updatePayload, type, oldProps) { | ||
updateInstanceFromProps(instance, updatePayload, oldProps); | ||
function commitUpdate(instance, type, oldProps, newProps) { | ||
updateInstanceFromProps(instance, type, oldProps, newProps); | ||
} | ||
@@ -258,2 +295,5 @@ | ||
const noContext = {}; | ||
let currentUpdatePriority = NoEventPriority; | ||
const reconciler = ReactReconciler({ | ||
@@ -272,6 +312,47 @@ supportsMutation: true, | ||
removeChild, | ||
insertInContainerBefore, | ||
insertBefore, | ||
noTimeout: -1, | ||
getInstanceFromNode() { | ||
return null; | ||
}, | ||
shouldAttemptEagerTransition() { | ||
return false; | ||
}, | ||
requestPostPaintCallback() {}, | ||
maySuspendCommit() { | ||
return false; | ||
}, | ||
preloadInstance() { | ||
return true; | ||
}, | ||
startSuspendingCommit() {}, | ||
suspendInstance() {}, | ||
waitForCommitToBeReady() { | ||
return null; | ||
}, | ||
setCurrentUpdatePriority(newPriority) { | ||
currentUpdatePriority = newPriority; | ||
}, | ||
getCurrentUpdatePriority() { | ||
return currentUpdatePriority; | ||
}, | ||
resolveUpdatePriority() { | ||
if (currentUpdatePriority) { | ||
return currentUpdatePriority; | ||
} | ||
return DefaultEventPriority; | ||
}, | ||
finalizeInitialChildren() { | ||
@@ -281,3 +362,5 @@ return false; | ||
getChildHostContext() {}, | ||
getChildHostContext() { | ||
return noContext; | ||
}, | ||
@@ -288,3 +371,5 @@ getPublicInstance(instance) { | ||
getRootHostContext() {}, | ||
getRootHostContext() { | ||
return noContext; | ||
}, | ||
@@ -314,5 +399,3 @@ getCurrentEventPriority() { | ||
const logRecoverableError = | ||
typeof reportError === 'function' | ||
? reportError // eslint-disable-line no-undef | ||
: console.error; // eslint-disable-line no-console | ||
typeof reportError === 'function' ? reportError : console.error; // eslint-disable-line no-console | ||
@@ -319,0 +402,0 @@ root = reconciler.createContainer( |
@@ -17,2 +17,3 @@ function arrayEquals(a, b) { | ||
options: true, | ||
ref: true, // TODO: deal with changing ref | ||
}; | ||
@@ -19,0 +20,0 @@ |
@@ -19,2 +19,3 @@ /** | ||
import {Component, createElement, createRef, forwardRef} from 'react'; | ||
import {MAP} from './internal/config.js'; | ||
import {render, updateInstanceFromProps} from './internal/render.js'; | ||
@@ -42,3 +43,3 @@ | ||
} | ||
updateInstanceFromProps(this.map, mapProps); | ||
updateInstanceFromProps(this.map, MAP, {}, mapProps); | ||
} | ||
@@ -45,0 +46,0 @@ |
{ | ||
"name": "@planet/maps", | ||
"version": "10.3.0-dev.1734966802191", | ||
"version": "10.3.0-dev.1735324425026", | ||
"description": "Declarative mapping components for React", | ||
@@ -25,3 +25,3 @@ "type": "module", | ||
"dependencies": { | ||
"react-reconciler": "^0.29.0" | ||
"react-reconciler": "^0.31.0" | ||
}, | ||
@@ -39,4 +39,4 @@ "peerDependencies": { | ||
"@testing-library/react": "^16.0.0", | ||
"@types/react": "^18.0.27", | ||
"@types/react-dom": "^18.0.10", | ||
"@types/react": "^19.0.2", | ||
"@types/react-dom": "^19.0.2", | ||
"@vitest/browser": "^2.0.3", | ||
@@ -56,4 +56,4 @@ "astro": "^4.0.3", | ||
"prop-types": "^15.8.1", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"react": "^19.0.0", | ||
"react-dom": "^19.0.0", | ||
"remark-html": "^16.0.1", | ||
@@ -60,0 +60,0 @@ "remark-parse": "^11.0.0", |
102153
1.59%2534
2.88%+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
Updated