{"id":15705513,"url":"https://github.com/jonathanhefner/taproot","last_synced_at":"2025-11-11T20:25:31.234Z","repository":{"id":57121951,"uuid":"380345262","full_name":"jonathanhefner/taproot","owner":"jonathanhefner","description":"Low-budget Stimulus knock-off","archived":false,"fork":false,"pushed_at":"2021-06-30T18:24:31.000Z","size":80,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-20T11:04:39.398Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/jonathanhefner.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}},"created_at":"2021-06-25T20:16:55.000Z","updated_at":"2021-07-16T12:51:09.000Z","dependencies_parsed_at":"2022-08-24T14:59:22.099Z","dependency_job_id":null,"html_url":"https://github.com/jonathanhefner/taproot","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanhefner%2Ftaproot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanhefner%2Ftaproot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanhefner%2Ftaproot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanhefner%2Ftaproot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonathanhefner","download_url":"https://codeload.github.com/jonathanhefner/taproot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253796037,"owners_count":21965643,"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":[],"created_at":"2024-10-03T20:16:37.916Z","updated_at":"2025-11-11T20:25:26.185Z","avatar_url":"https://github.com/jonathanhefner.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Taproot\n\nA low-budget [Stimulus](https://stimulus.hotwire.dev/) knock-off,\nweighing in at 6 kB minified / 2.5 kB minified + gzipped.\n\nThe key differences are:\n\n* The core HTML attributes are `data-controllers` and `data-actions`,\n  instead of `data-controller` and `data-action`.  This lets you test\n  drive Taproot and Stimulus at the same time, if desired.\n\n* The `data-actions` syntax is:\n\n    ```html\n    \u003cdiv data-actions=\"kebab-case-controller:kebab-case-method@event [...]\" /\u003e\n    ```\n\n  Modifiers such as `+once` or `+passive` can be appended to the event.\n  Likewise, the event target can be changed by appending `+document` or\n  `+window` to the event.\n\n* Implicit events are not supported, but commas can be used as shorthand\n  to bind multiple actions to the same event:\n\n    ```html\n    \u003cdiv data-actions=\"selection:all,clipboard:copy@click\" /\u003e\n    ```\n\n  Likewise, commas can be used as shorthand to bind the same action to\n  multiple events:\n\n    ```html\n    \u003cinput type=\"text\" data-actions=\"autocomplete:suggest@change,keyup\" /\u003e\n    ```\n\n* Namespaced data attributes on the controller element can be accessed\n  via a controller's `data` property.  Default values can be specified\n  via a static `defaults` property on the controller.  A default value\n  that is neither a string nor `undefined` indicates that attribute\n  should be deserialized with `JSON.parse` when reading, and serialized\n  with `JSON.stringify` when writing.  For example:\n\n    ```javascript\n    class BottlesController extends Taproot.Controller {\n      static defaults = { count: 99 }\n\n      decrement() {\n        this.data.count -= 1\n      }\n    }\n    ```\n\n  If the `data-bottles-count` attribute is not present on the controller\n  element, `this.data.count` will return `99`.  Otherwise, it will\n  return the value of `data-bottles-count` parsed by `JSON.parse`.\n\n* Controllers provide a `dataFor` method that returns a proxy object\n  which is similar to the `data` object for any element.  For example:\n\n    ```javascript\n    class BottlesController extends Taproot.Controller {\n      static defaults = { count: 99 }\n\n      takeN({ currentTarget }) {\n        this.data.count -= this.dataFor(currentTarget, { n: 1 }).n\n      }\n    }\n    ```\n\n  If the `data-bottles-n` attribute is not present on `currentTarget`,\n  `this.dataFor(currentTarget, { n: 1 }).n` will return `1`.  Otherwise,\n  it will return the value of `data-bottles-n` parsed by `JSON.parse`.\n  If the defaults argument is not specified, `dataFor` will use the\n  controller's static `defaults`.\n\n* The `nodes` and `nodeSets` controller properties can be used to query\n  for nodes that have a particular namespaced attribute.  For example:\n\n    ```javascript\n    class BottlesController extends Taproot.Controller {\n      static defaults = { count: 99 }\n\n      countChanged({ count }) {\n        const { status } = this.nodes\n        if (status) status.textContent = `${count} bottles of beer on the wall.`\n      }\n    }\n    ```\n\n    `this.nodes.status` will return the first node in the controller\n    element tree that has a `data-bottles-status` attribute.\n\n* A controller's `connect` and `disconnect` methods will be invoked only\n  if they reflect the state of the controller element at the time of\n  invocation.  For example:\n\n    ```javascript\n    class ItemController extends Taproot.Controller {\n      connect() { /* ... */ }\n      disconnect() { /* ... */ }\n\n      moveToTop() {\n        this.element.parentElement.prepend(this.element)\n      }\n\n      remove() {\n        this.element.remove()\n      }\n    }\n    ```\n\n  `moveToTop` generates two DOM mutation events because `prepend`\n  removes the controller element from the DOM before prepending it to\n  `parentElement`.  However, at the time both mutation events are\n  processed, the controller element is no longer disconnected from the\n  DOM, so neither `disconnect` nor `connect` will be invoked.\n\n  On the other hand, `remove` permanently removes the controller element\n  from the DOM.  When its corresponding mutation event is processed,\n  `disconnect` will be invoked.\n\n* The `Taproot.register` method accepts an object that maps controller\n  descriptors to constructors.  It also automatically kebab-cases the\n  given descriptors and strips their `-controller` suffix.  Thus, for\n  example, the following are all equivalent:\n\n    ```javascript\n    import * as Taproot from \"@jonathanhefner/taproot\"\n    import { FooController, BarController } from \"./foo-and-bar.js\"\n\n    Taproot.register({ foo: FooController, bar: BarController })\n    ```\n\n    ```javascript\n    import * as Taproot from \"@jonathanhefner/taproot\"\n    import { FooController as foo, BarController as bar } from \"./foo-and-bar.js\"\n\n    Taproot.register({ foo, bar })\n    ```\n\n    ```javascript\n    import * as Taproot from \"@jonathanhefner/taproot\"\n    import { FooController, BarController } from \"./foo-and-bar.js\"\n\n    Taproot.register({ FooController, BarController })\n    ```\n\n    ```javascript\n    import * as Taproot from \"@jonathanhefner/taproot\"\n    import * as fooAndBar from \"./foo-and-bar.js\"\n\n    Taproot.register(fooAndBar)\n    ```\n\n  `Taproot.register` can also accept a non-anonymous constructor, and\n  use its name as the descriptor.  For example:\n\n    ```javascript\n    import { register, Controller } from \"@jonathanhefner/taproot\"\n\n    register(class BottlesController extends Controller {\n      /* ... */\n    })\n    ```\n\n  will register the `bottles` descriptor to `BottlesController`.\n\n* The `Taproot.register` method also acts as a \"start\" method.  Taproot\n  will not start any observers or perform any initialization until after\n  `register` is called.  When `register` is called, Taproot schedules a\n  (re-)evaluation of all `data-controllers` elements after the current\n  JavaScript task.  Therefore, `register` can be called at any time, and\n  additional calls within the same JavaScript task do not incur\n  additional overhead.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonathanhefner%2Ftaproot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonathanhefner%2Ftaproot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonathanhefner%2Ftaproot/lists"}