{"id":27376284,"url":"https://github.com/julesguesnon/bs-intersection-observer","last_synced_at":"2025-04-13T12:36:15.471Z","repository":{"id":57190538,"uuid":"204458385","full_name":"JulesGuesnon/bs-intersection-observer","owner":"JulesGuesnon","description":":fire: Bindings for IntesectionObserver api","archived":false,"fork":false,"pushed_at":"2019-09-01T16:14:00.000Z","size":9,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-21T15:52:12.309Z","etag":null,"topics":["bucklescript","bucklescript-bindings","intersection-observer","reasonml"],"latest_commit_sha":null,"homepage":"","language":"OCaml","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JulesGuesnon.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":"2019-08-26T11:10:00.000Z","updated_at":"2019-09-01T16:14:02.000Z","dependencies_parsed_at":"2022-09-15T06:51:07.289Z","dependency_job_id":null,"html_url":"https://github.com/JulesGuesnon/bs-intersection-observer","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JulesGuesnon%2Fbs-intersection-observer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JulesGuesnon%2Fbs-intersection-observer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JulesGuesnon%2Fbs-intersection-observer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JulesGuesnon%2Fbs-intersection-observer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JulesGuesnon","download_url":"https://codeload.github.com/JulesGuesnon/bs-intersection-observer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248715204,"owners_count":21150059,"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":["bucklescript","bucklescript-bindings","intersection-observer","reasonml"],"created_at":"2025-04-13T12:36:14.731Z","updated_at":"2025-04-13T12:36:15.465Z","avatar_url":"https://github.com/JulesGuesnon.png","language":"OCaml","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bs-intersection-observer\n\nthis package make the bindings for the IntersectionObserver api.\n\n## How to install ?\n\n```\nnpm install bs-intersection-observer --save\n```\n\n```bash\nyarn add bs-intersection-observer\n```\n\nThen add the dependency to you `bsconfig.json`\n\n```json\n\"bs-dependencies\": [\n\t\"bs-intersection-observer\"\n],\n```\n\n## How to use it ?\n\n### What the package contains ?\n\nUnder the module `BsIntersectionObserver`, you'll find 2 sub module:\n\n#### Types\n\n`Types` is pretty obvious, it contains all the types related to the `IntersectionObserver`. You'll notice that under type there's:\n\n-   `JsT` : Javascript types\n-   `T` : Reason types\n\n#### Create\n\nProbably the one you're looking for. `Create` contains two functions:\n\n-   `newIntersectionObserver` : the direct binding from Js\n-   `intersectionObserver` : the IntersectionObserver adapted to Reason with some nice completion (the one you want to call)\n\n### Example with reason-react\n\n```reason\n[@bs.val] [@bs.scope \"document\"]\nexternal querySelector: string =\u003e Dom.element = \"querySelector\";\n\n[@react.component]\nlet make = () =\u003e {\n  let observer =\n    BsIntersectionObserver.Create.intersectionObserver(\n      ~cb=\n        (entries, _) =\u003e {\n          Belt.Array.map(entries, entry =\u003e\n            if (entry.intersectionRatio \u003e 0.) {\n              Js.log(\"Visible element\");\n            } else {\n              Js.log(\"Not visible element\");\n            }\n          )\n          -\u003eignore;\n          ();\n        },\n      ~options=None,\n    );\n  React.useEffect1(\n    () =\u003e {\n      let el = querySelector(\".hello\");\n      observer.observe(el);\n      Some(() =\u003e observer.unobserve(el));\n    },\n    [||],\n  );\n\n  \u003cdiv className=\"hello\"\u003e \"Hello world\"-\u003eReasonReact.string \u003c/div\u003e;\n};\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjulesguesnon%2Fbs-intersection-observer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjulesguesnon%2Fbs-intersection-observer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjulesguesnon%2Fbs-intersection-observer/lists"}