{"id":19715532,"url":"https://github.com/hudson-newey/2.js","last_synced_at":"2025-10-15T15:15:36.061Z","repository":{"id":206648823,"uuid":"717281352","full_name":"hudson-newey/2.js","owner":"hudson-newey","description":"A library to bring reactive state to JavaScript with minimal assumptions, and overhead","archived":false,"fork":false,"pushed_at":"2024-10-01T11:34:38.000Z","size":374,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-05T23:50:46.698Z","etag":null,"topics":["framework","framwork-javascript","javascript","javascript-library","js","library","ts","typescript","web"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@hudson-newey/2.js","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hudson-newey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-11-11T01:57:11.000Z","updated_at":"2024-10-01T11:34:42.000Z","dependencies_parsed_at":"2024-03-19T12:53:47.501Z","dependency_job_id":null,"html_url":"https://github.com/hudson-newey/2.js","commit_stats":null,"previous_names":["hudson-newey/2.js"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hudson-newey%2F2.js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hudson-newey%2F2.js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hudson-newey%2F2.js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hudson-newey%2F2.js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hudson-newey","download_url":"https://codeload.github.com/hudson-newey/2.js/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233363309,"owners_count":18664960,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["framework","framwork-javascript","javascript","javascript-library","js","library","ts","typescript","web"],"created_at":"2024-11-11T22:38:38.312Z","updated_at":"2025-09-17T09:31:46.413Z","avatar_url":"https://github.com/hudson-newey.png","language":"TypeScript","readme":"# 2.js\n\nA highly efficient library to bring reactive state to JavaScript with minimal overhead and bundle size that can be imported via HTML `\u003cscript src=\"\"\u003e` tags.\n\n### Minimal Increment-Decrement Counter\n\n```html\n\u003cp\u003eCount: \u003cspan id=\"count-output\"\u003e\u003c/span\u003e\u003c/p\u003e\n\u003cbutton onclick=\"page['#count-output']++\"\u003eIncrement\u003c/button\u003e\n\u003cbutton onclick=\"page['#count-output']--\"\u003eDecrement\u003c/button\u003e\n\n\u003cscript\u003e\n    const page = new Component({\n        \"#count-output\": 0,\n    });\n\u003c/script\u003e\n```\n\nOR\n\n```html\n\u003cp\u003eCount: \u003cspan @count\u003e\u003c/span\u003e\u003c/p\u003e\n\u003cbutton onclick=\"page.count++\"\u003eIncrement\u003c/button\u003e\n\u003cbutton onclick=\"page.count--\"\u003eDecrement\u003c/button\u003e\n\n\u003cscript\u003e\n    const page = new Component({\n        count: 0,\n    });\n\u003c/script\u003e\n```\n\n### Collapsable Elements\n\n```html\n\u003cbutton onclick=\"app.toggleElement()\"\u003eClick Me\u003c/button\u003e\n\u003cdiv @collapsableElement\u003e\u003c/div\u003e\n\n\u003cscript\u003e\n    const app = new Component({\n        collapsableElement: null,\n        toggleElement: () =\u003e\n            (app.collapsableElement = app.collapsableElement\n                ? null\n                : \"\u003ch1\u003eHello World\u003c/h1\u003e\"),\n    });\n\u003c/script\u003e\n```\n\n### For Loops\n\n```html\n\u003ch1\u003eMy Shopping List\u003c/h1\u003e\n\u003cdiv @shoppingListTemplate\u003e\u003c/div\u003e\n\n\u003cscript\u003e\n    const shoppingItems = [\n        \"bread\",\n        \"milk\",\n        \"eggs\",\n        \"cheese\",\n        \"butter\",\n        \"chicken\",\n    ];\n\n    const app = new Component({\n        shoppingListTemplate: `\n            \u003cul\u003e\n                ${map(shoppingItems, (item) =\u003e `\u003cli\u003e${item}\u003c/li\u003e`)}\n            \u003c/ul\u003e\n        `,\n    });\n\u003c/script\u003e\n```\n\n### Single Page Application (SPA)\n\n```html\n\u003cmain\u003e\n    \u003cnav\u003e\n        \u003cbutton onclick=\"app.setPage(homePage)\"\u003eHome\u003c/button\u003e\n        \u003cbutton onclick=\"app.setPage(aboutPage)\"\u003eAbout\u003c/button\u003e\n    \u003c/nav\u003e\n\n    \u003cdiv\u003e\n        \u003ch1 @name\u003e\u003c/h1\u003e\n        \u003cp @description\u003e\u003c/p\u003e\n    \u003c/div\u003e\n\u003c/main\u003e\n\n\u003cscript\u003e\n    const homePage = {\n        name: \"Home\",\n        description: \"This is the home page\",\n    };\n\n    const aboutPage = {\n        name: \"About\",\n        description: \"About this company\",\n    };\n\n    const app = new Component({\n        name: homePage.name,\n        description: homePage.description,\n        setPage: (value) =\u003e {\n            app.name = value.name;\n            app.description = value.description;\n        },\n    });\n\u003c/script\u003e\n```\n\n### Simple Todo App\n\n```html\n\u003ch1\u003eAdd Todo Item\u003c/h1\u003e\n\n\u003cinput\n    id=\"taskNameInput\"\n    type=\"text\"\n    onkeyup=\"((e) =\u003e e.key === 'Enter' \u0026\u0026 app.addTodoItem())(event)\"\n/\u003e\n\u003cbutton onclick=\"app.addTodoItem()\"\u003eAdd Todo Item\u003c/button\u003e\n\n\u003cdiv\u003e\n    \u003ch2\u003eTodo Items\u003c/h2\u003e\n    \u003cdiv @todoListTemplate\u003e\u003c/div\u003e\n\u003c/div\u003e\n\n\u003cscript\u003e\n    const app = new Component({\n        todoItems: [],\n        addTodoItem: () =\u003e {\n            if (!taskNameInput.value) return;\n\n            app.todoItems.push(taskNameInput.value);\n\n            // in the regular DOM model, whenever an element on the document is created with an id\n            // a variable is created in the global scope with the same name as the id\n            // this variable can be used to access the element directly without document.getElementById()\n            app.todoListTemplate = app.todoItems;\n            taskNameInput.value = \"\";\n        },\n        // this value has an \"operator function\"\n        // that means that any values assigned to it will be passed through the function first\n        // because this is technically a value, it can have DOM bindings\n        todoListTemplate: (incomingTodoItems) =\u003e `\n            \u003cul\u003e\n                ${map(app.todoItems, (item) =\u003e `\u003cli\u003e${item}\u003c/li\u003e`)}\n            \u003c/ul\u003e\n        `,\n    });\n\u003c/script\u003e\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhudson-newey%2F2.js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhudson-newey%2F2.js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhudson-newey%2F2.js/lists"}