Skip to content
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

react-reconciler update #32

Merged
merged 1 commit into from
May 24, 2018
Merged
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
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,27 @@
},
"homepage": "https://github.com/a-ignatov-parc/tvdml#readme",
"dependencies": {
"react-reconciler": "^0.8.0"
"react-reconciler": "^0.11.0"
},
"devDependencies": {
"babel-core": "^6.22.1",
"babel-loader": "^7.1.2",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-register": "^6.26.0",
"eslint": "^4.13.1",
"eslint": "^4.19.1",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-import": "^2.12.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.5.1",
"eslint-plugin-react": "^7.8.2",
"mocha": "^4.0.1",
"mocha-junit-reporter": "^1.15.0",
"react": "^16.3.0",
"react": "^16.4.0",
"uglifyjs-webpack-plugin": "^1.1.4",
"webpack": "^3.10.0"
},
"peerDependencies": {
"react": "^16.3.0"
"react": "^16.4.0"
},
"files": [
"dist"
Expand Down
290 changes: 145 additions & 145 deletions src/react-tvml/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,174 +400,174 @@ const TVMLRenderer = ReactFiberReconciler({

now: () => Date.now(),

mutation: {
commitMount(domElement, type, newProps) {
console.info(
'commitMount',
domElement,
type,
newProps,
);
},

commitUpdate(domElement, updatePayload, type, oldProps, newProps) {
updateProperties(domElement, updatePayload, type, oldProps, newProps);
},

resetTextContent(domElement) {
domElement.textContent = '';
},

commitTextUpdate(textInstance, oldText, newText) {
let target;
isPrimaryRenderer: true,

/**
* If text node update is commited we need to check if there any
* reference text nodes to figure out which one to update.
*/
if (textInstance._targetTextNode) {
target = textInstance._targetTextNode;
} else if (textInstance._handledTextNodes) {
target = textInstance;
}
scheduleDeferredCallback(callback) {
return setTimeout(() => {
callback({
timeRemaining() {
return Infinity;
},
});
});
},

if (target) {
const nodes = target._handledTextNodes;
const reference = nodes.find(({ node }) => node === textInstance);
cancelDeferredCallback(timeoutId) {
clearTimeout(timeoutId);
},

reference.value = newText;
updateNodeValue(target);
} else {
textInstance.nodeValue = newText;
}
},
supportsMutation: true,
supportsPersistence: false,

appendChild(parentInstance, child) {
const target = parentInstance.lastChild;
commitMount(/* domElement, type, newProps */) {
// noop
},

/**
* If we need to attach text node in update we performing same checks
* as in `appendInitialChild`.
*/
if (isTextNode(target) && isTextNode(child)) {
if (!target._handledTextNodes) {
target._handledTextNodes = [{
node: target,
value: target.nodeValue,
}];
}
commitUpdate(domElement, updatePayload, type, oldProps, newProps) {
updateProperties(domElement, updatePayload, type, oldProps, newProps);
},

target._handledTextNodes.push({
node: child,
value: child.nodeValue,
});
resetTextContent(domElement) {
domElement.textContent = '';
},

child._targetTextNode = target;
}
commitTextUpdate(textInstance, oldText, newText) {
let target;

parentInstance.appendChild(child);
},
/**
* If text node update is commited we need to check if there any
* reference text nodes to figure out which one to update.
*/
if (textInstance._targetTextNode) {
target = textInstance._targetTextNode;
} else if (textInstance._handledTextNodes) {
target = textInstance;
}

appendChildToContainer(container, child) {
if (container.nodeType === COMMENT_NODE) {
container.parentNode.insertBefore(child, container);
} else {
container.appendChild(child);
}
},
if (target) {
const nodes = target._handledTextNodes;
const reference = nodes.find(({ node }) => node === textInstance);

insertBefore(parentInstance, child, beforeChild) {
/**
* When in TVML text node is inserted before another text node its value
* will be merged with existed and it will be removed.
*
* Check `appendInitialChild` for more info.
*/
if (isTextNode(beforeChild) && isTextNode(child)) {
if (!beforeChild._handledTextNodes) {
beforeChild._handledTextNodes = [{
node: beforeChild,
value: beforeChild.nodeValue,
}];
}
reference.value = newText;
updateNodeValue(target);
} else {
textInstance.nodeValue = newText;
}
},

beforeChild._handledTextNodes.unshift({
node: child,
value: child.nodeValue,
});
appendChild(parentInstance, child) {
const target = parentInstance.lastChild;

child._targetTextNode = beforeChild;
/**
* If we need to attach text node in update we performing same checks
* as in `appendInitialChild`.
*/
if (isTextNode(target) && isTextNode(child)) {
if (!target._handledTextNodes) {
target._handledTextNodes = [{
node: target,
value: target.nodeValue,
}];
}

parentInstance.insertBefore(child, beforeChild);
},
target._handledTextNodes.push({
node: child,
value: child.nodeValue,
});

child._targetTextNode = target;
}

insertInContainerBefore(container, child, beforeChild) {
if (container.nodeType === COMMENT_NODE) {
container.parentNode.insertBefore(child, beforeChild);
} else {
container.insertBefore(child, beforeChild);
parentInstance.appendChild(child);
},

appendChildToContainer(container, child) {
if (container.nodeType === COMMENT_NODE) {
container.parentNode.insertBefore(child, container);
} else {
container.appendChild(child);
}
},

insertBefore(parentInstance, child, beforeChild) {
/**
* When in TVML text node is inserted before another text node its value
* will be merged with existed and it will be removed.
*
* Check `appendInitialChild` for more info.
*/
if (isTextNode(beforeChild) && isTextNode(child)) {
if (!beforeChild._handledTextNodes) {
beforeChild._handledTextNodes = [{
node: beforeChild,
value: beforeChild.nodeValue,
}];
}
},

removeChild(parentInstance, child) {
beforeChild._handledTextNodes.unshift({
node: child,
value: child.nodeValue,
});

child._targetTextNode = beforeChild;
}

parentInstance.insertBefore(child, beforeChild);
},

insertInContainerBefore(container, child, beforeChild) {
if (container.nodeType === COMMENT_NODE) {
container.parentNode.insertBefore(child, beforeChild);
} else {
container.insertBefore(child, beforeChild);
}
},

removeChild(parentInstance, child) {
/**
* If we deleting text node with parent node then we just clearing any
* references. No need to use `removeChild` because it was never attached
* to document.
*
* Also we can't remove parent node with active references. But we can
* empty its value.
*/
if (child._targetTextNode) {
const target = child._targetTextNode;
const nodes = target._handledTextNodes;
const referenceIndex = nodes.findIndex(({ node }) => node === child);

nodes.splice(referenceIndex, 1);
delete child._targetTextNode;
updateNodeValue(target);
} else if (child._handledTextNodes && child._handledTextNodes.length) {
const nodes = child._handledTextNodes;
const reference = nodes.find(({ node }) => node === child);

reference.value = '';
updateNodeValue(child);
} else {
parentInstance.removeChild(child);
}
},

removeChildFromContainer(container, child) {
if (container.nodeType === COMMENT_NODE) {
container.parentNode.removeChild(child);
} else if (container.nodeType === DOCUMENT_NODE) {
/**
* If we deleting text node with parent node then we just clearing any
* references. No need to use `removeChild` because it was never attached
* to document.
*
* Also we can't remove parent node with active references. But we can
* empty its value.
* Starting from tvOS 11.3 if we try to remove children from dismissed
* document we'll get uncaught exception.
*/
if (child._targetTextNode) {
const target = child._targetTextNode;
const nodes = target._handledTextNodes;
const referenceIndex = nodes.findIndex(({ node }) => node === child);

nodes.splice(referenceIndex, 1);
delete child._targetTextNode;
updateNodeValue(target);
} else if (child._handledTextNodes && child._handledTextNodes.length) {
const nodes = child._handledTextNodes;
const reference = nodes.find(({ node }) => node === child);

reference.value = '';
updateNodeValue(child);
} else {
parentInstance.removeChild(child);
}
},

removeChildFromContainer(container, child) {
if (container.nodeType === COMMENT_NODE) {
container.parentNode.removeChild(child);
} else if (container.nodeType === DOCUMENT_NODE) {
/**
* Starting from tvOS 11.3 if we try to remove children from dismissed
* document we'll get uncaught exception.
*/
if (container.isAttached) {
container.removeChild(child);
}
} else {
if (container.isAttached) {
container.removeChild(child);
}
},
},

scheduleDeferredCallback(callback) {
return setTimeout(() => {
callback({
timeRemaining() {
return Infinity;
},
});
});
} else {
container.removeChild(child);
}
},

cancelDeferredCallback(timeoutId) {
clearTimeout(timeoutId);
},
supportsHydration: false,
});

class ReactRoot {
Expand Down
Loading