Giter VIP home page Giter VIP logo

poor-man-jsx's Introduction

Hi ๐Ÿ‘‹

I'm Shin, a web developer based in the Philippines.

I am a licensed civil engineer but found my passion in web development. I was first introduced to programming during my first year then picked it up a semester later as a hobby because I thought it can help me improve my problem solving skills. I used what I learned to do some of my math homeworks. It was during the pandemic that I started studying programming seriously. I took CS50 then The Odin Project and here I am now. I specialize in JavaScript but has a solid foundation on front-end with experience on backend with Node.js.

Skills

JavaScript HTML5 CSS TailwindCSS React Node.js Express MongoDB Firebase Webpack npm Git Jest Figma

Shin's GitHub stats GitHub Streak

poor-man-jsx's People

Contributors

lemonadee71 avatar

Stargazers

 avatar

Watchers

 avatar

poor-man-jsx's Issues

Add ability to add hooks to elements

Currently, you need to make a Template to add hooks. It'd be good if we can add them to manually created or existing elements like how we can add lifecycle listeners.

Placeholders for custom-component aren't replaced correctly

I have this code

  <my-icon
    name="kebab"
    id="taskmenu-xv1box7npfe7bj4e"
    title="Task menu"
    class="stroke-gray-500 hover:stroke-gray-800 dark:hover:stroke-gray-300"
  ></my-icon>

Which results in

<custom-component name="kebab" id="taskmenu-rfkbdcguwcxnkjto" title="Task menu" class="stroke-gray-500 hover:stroke-gray-800 dark:hover:stroke-gray-300"></custom-component>

The issue is that there is no :is attribute which I suspect due to the regex and replace function.

Can't find node using selector error

I'm getting this weird behavior for my todo project. This bug is also present for the legacy version. I don't know what's causing it. There seems to be no visible effect whatsoever if we just ignore the error by doing if (!el) return; for createElementFromString.

The error went away after a while.

Screenshot from 2021-08-12 21-18-12

Add method forwarding

Add method forwarding for hooks. Atm, to work with arrays, we have to do this:

data.$items(items => items.map(callback))

With method forwarding, this could be shortened to:

data.$items.map(callback)

Allow passing of `Template` directly to hooks again

We removed this because it creates a circular dependency but there's a way to fix that. We can separate the children part of modifyElement to a new file/function and also separate html from createElement. Then in createElement, we have our simpler version of children since all the other stuff is only needed when dealing with hooks.

Expose hydration function

Similar to addHooks. This is so we can provide an easy way to set an element's properties using an object.

Rename `state`

I think using the term state with the current usage is wrong. We are more like binding an object to an element (updating the element when the object is updated). Maybe hooks are better?

Create watch function

Add a function that allows to watch a hook and invoke a callback if there is a change without needing it to hook to an element.

Add additional directives

Add if-else and show directive like in Vue. This is to simplify commonly used patterns. So this

html`<div style_display=${hook.$show(val => val ? 'block' : 'none')}>Hello, World</div>`

can be simplified with show directive to this

html`<div :show=${hook.$show}>Hello, World</div>`

Also, I suggest using colon (:) as prefix for directives to signify that they are not normal attributes. Directives are declared as attributes but shouldn't show as such when the element is rendered. For example, the previous example if hook.show = false should be rendered as

<div style="display: none;">Hello, World</div>

This means that text, html, and children should also use colon since they are directives.

Add text tag utility for hooks

Since we deal with string a lot with hooks, for convenience, we should create a text tag to turn this

$textContent: hook.$prop(str => `Some string ${str}`)

to this

$textContent: text`Some string ${hook.$prop}`

which is more concise. Both ways are valid. Tag name subject to change.

Anything that follows a self-closing custom component is removed

I have this code

 <div class="group w-52 p-3 space-y-2">
    <my-icon name="kanban" class="stroke-sky-500 group-hover:stroke-sky-600 mx-auto" size="130" decorative="true" /> 
    <h3 class="font-medium text-xl text-center">Kanban boards</h3>
    <p class="text-neutral-700 text-center">
      Inspired by desktop app for
      <a
        class="underline hover:text-black"
        href="https://chrome.google.com/webstore/detail/desktop-app-for-google-ta/lpofefdiokgmcdnnaigddelnfamkkghi?hl=en"
      >
        Google Tasks
      </a>
      , easily manage tasks on a Kanban board
    </p>
  </div>

And anything that follows my-icon is not rendered. You can test this by moving the custom component in the order.

Allow text nodes in diffing

Currently, to avoid complexity we need all elements under is-list to have their text inside an element so we can just set their innerHTML when the text changed. Related to #24 since if we allow that behavior, it should be acceptable in diffing too. One caveat is that this might require significant change in the way we approach diffing but refactor is due since I'd like to try optimizing it too. And fix #27 first before proceeding and make sure no there are no unnecessary renders.

Allow passing of hook directly to body

Currently, to hook to children we have to do this

const List = () => html`<ul ${{ $children: hook.$items.map(item => ListItem(item)) }}></ul>`

This can get ugly and cluttered. A more concise syntax would be

const List = () => html`<ul>${hook.$items.map(item => ListItem(item))}</ul>`

This should also work for strings since we can pass strings to append so we don't need to use textContent too.

Add options to event listeners

This is inspired by other frameworks. Atm, I think it should look like

{
    'onSubmit.prevent': callback,
    // For multiple
    'onClick.[once,capture]': callback,
}

Allow method chaining for hooks

We should be able to do this:

const [test] = createHook({ str: "my test string" });
test.$str.split(" ").reverse().join();

`replaceWith` mutates elements and breaks diffing for consecutive elements that needs update

If we have

<div>
    <p>Some text</p>
    <p>Another text</p>
<div>

then replace it with

<div>
    <p>Some edited text</p>
    <p>Another text</p>
<div>

it will throw an error because what happens is that when <p>Some text</p> is replaced with <p>Some edited text</p>, the latter is removed from the new node so the newNode.children changes causing the next element (<p>Another text</p>) to be replaced with undefined because newNode.children[1] does not exist.

Using method forwarding creates elements for up to 9 times

When I replace this

html`
<div is-list keystring="id">
  ${project.$lists((lists) => lists.map(List))}
</div>
`

with

html`
<div is-list keystring="id"> 
  ${project.$lists.map(List)}
</div>
`

It creates List for 8-9 times each but mounts once. Nested is-list components are not affected, just the direct component passed with the hook.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.