Skip to content

Instantly share code, notes, and snippets.

View Tevinthuku's full-sized avatar
🤓
typing fast

Tev Tevinthuku

🤓
typing fast
View GitHub Profile
@Tevinthuku
Tevinthuku / unique_in_order.py
Created January 29, 2019 17:53
Implement the function unique_in_order which takes as argument a sequence and returns a list of items without any elements with the same value next to each other and preserving the original order of elements.
def unique_in_order(iterable):
listofargs = [x for x in (list(iterable))]
uniqueList = []
prevItem = None
for item in listofargs:
if item == prevItem:
prevItem = item
continue
else:
uniqueList.append(item)
{
"main": "dist/tevreact.umd.js",
"module": "dist/tevreact.es.js", // ESM-aware tools like Rollup need this field to import the es module directly
"name": "tevreact",
"version": "1.0.0",
"license": "MIT",
"files": [
"dist"
],
"scripts": {
@Tevinthuku
Tevinthuku / .babelrc
Last active August 27, 2019 16:50
Full project setup.
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
]
//NB: ALL DOM nodes have their corresponding fibers in our new implementation
// most of this properties will make sense once we begin using them
let fiber = {
tag: HOST_COMPONENT, // we can have either host of class component
type: "input",
parent: parentFiber, // the parentNode’s fiber
child: childFiber, // the childNode’s fiber if it has any
sibling: null, // the element that is in the same tree level as this input
alternate: currentFiber, // the fiber that has been rendered on the dom. Will be null if its on initial render
stateNode: document.createElement(“div”),
const rootElement = document.getElementById("root")
ReactDom.render(<Component />, rootElement) // renders for the first time
ReactDom.render(<Component />, rootElement) // does the app component render twice
$ yarn init -y // if you have yarn installed
$ npm init -y // if you have npm
// install rollup
$ yarn add rollup —-dev
$ npm install rollup —-save-dev
const root = document.getElementById("root")
ReactDom.render(<Component />, root)
@Tevinthuku
Tevinthuku / reconciler.js
Last active August 14, 2019 17:24
reconciling children
// .. code
const PLACEMENT = "PLACEMENT"; // this is for a child that needs to be added
const DELETION = "DELETION"; //for a child that needs to be deleted.
const UPDATE = "UPDATE"; // for a child that needs to be updated. refresh the props
function createArrayOfChildren(children) {
// we can pass children as an array now in the call to render
/**
function performWork(deadline) {
if (!nextUnitOfWork) {
// on initial render
// or if all work is complete and the nextUnitOfWork is null
//grab the first item on the workInProgress queue.
initialUnitOfWork();
}
loopThroughWork(deadline)
if (nextUnitOfWork || workQueue.length > 0) {
// if theres more work to be done. get to know when the browser will be occupied
const CLASS_COMPONENT = "class";
// ...code
export function scheduleUpdate(instance, partialState) {
workQueue.push({
from: CLASS_COMPONENT, // we know scheduleUpdate came from a class so we have CLASS_COMPONENT here.
instance: instance, // *this* object
partialState: partialState // this represents the state that needs to be changed
});
requestIdleCallback(performWork);