Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: DOM Observer #8

Merged
merged 17 commits into from
Feb 9, 2024
Merged

Feature: DOM Observer #8

merged 17 commits into from
Feb 9, 2024

Conversation

jorenrui
Copy link
Contributor

@jorenrui jorenrui commented Feb 6, 2024

Description

Adds a DOM Observer that detects added and removed DOM nodes and applies / removes MiniJS bindings.

Demo

Demo below uses the Observer Demo HTML

Screen.Recording.2024-02-06.at.12.52.43.PM.mov

Summary by CodeRabbit

  • New Features
    • Introduced a demo observer functionality for interacting with a list of items dynamically.
    • Implemented observeDOM to track and respond to DOM changes, with support for older browsers.
📦 Published PR as canary version: 1.0.1-canary.8.ad24fea.0

✨ Test out this PR locally via:

npm install tonic-minijs@1.0.1-canary.8.ad24fea.0
# or 
yarn add tonic-minijs@1.0.1-canary.8.ad24fea.0

@jorenrui jorenrui self-assigned this Feb 6, 2024
Copy link

coderabbitai bot commented Feb 6, 2024

Walkthrough

The recent update brings an observer functionality to a demo, enhances an entity library with new methods and refactoring, and integrates DOM observation in the main library. It focuses on improving interactivity with dynamic list manipulation and ensuring efficient detection and response to changes in the document's structure.

Changes

File Summary
demo/.../observer.html New file implementing observer functionality for dynamic interaction with a list of items.
lib/entity.js Added initChildren, isInsideEachElement, refactored iteration, and added dispose method.
lib/generators/observer.js Introduces observeDOM function for tracking DOM changes with MutationObserver or fallback.
lib/main.js Added DOM observation functions and improved script identification and element filtering.

🐰✨
In the code where bytes do dance,
A change does come, it's not by chance.
Observers watch with keenest eyes,
As our digital world grows wise.
🌟🐇

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 7

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 33aed90 and c5816c7.
Files selected for processing (4)
  • demo/observer.html (1 hunks)
  • lib/entity.js (4 hunks)
  • lib/generators/observer.js (1 hunks)
  • lib/main.js (5 hunks)
Additional comments: 6
demo/observer.html (1)
  • 7-7: Verify the path to minijs.umd.js is correct relative to the demo file's location.
lib/main.js (1)
  • 101-101: Confirm that _listenToDOMChanges is called at the appropriate time during initialization for the desired effect.
lib/entity.js (4)
  • 55-57: Using spread operator on this.dynamicAttributes and CUSTOM_ATTRIBUTES is correct, but ensure CUSTOM_ATTRIBUTES are properly defined and used within the context.
  • 207-217: initChildren method correctly initializes child elements. Verify that it's called in the appropriate places to ensure all child elements are initialized.
  • 219-228: isInsideEachElement method correctly checks for parent elements with :each attribute. Confirm that this method is used effectively to prevent unnecessary initializations.
  • 270-270: The call to initChildren in evaluateEach is appropriate. Ensure that this does not lead to duplicate initializations or performance issues with large DOM structures.

lib/generators/observer.js Outdated Show resolved Hide resolved
lib/generators/observer.js Outdated Show resolved Hide resolved
demo/observer.html Show resolved Hide resolved
demo/observer.html Show resolved Hide resolved
lib/main.js Show resolved Hide resolved
lib/main.js Show resolved Hide resolved
lib/entity.js Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c5816c7 and eb1631a.
Files selected for processing (1)
  • lib/generators/observer.js (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • lib/generators/observer.js

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between eb1631a and fee22b1.
Files selected for processing (3)
  • demo/observer.html (1 hunks)
  • lib/entity.js (6 hunks)
  • lib/generators/interpreter.js (1 hunks)
Files skipped from review due to trivial changes (1)
  • lib/generators/interpreter.js
Files skipped from review as they are similar to previous changes (2)
  • demo/observer.html
  • lib/entity.js

@jorenrui jorenrui merged commit 5bc7ddb into main Feb 9, 2024
1 check passed
@jorenrui jorenrui deleted the jr.feature/dom-observer branch February 9, 2024 03:37
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 4

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between fee22b1 and 6d910a9.
Files selected for processing (1)
  • lib/entity.js (6 hunks)
Additional comments: 1
lib/entity.js (1)
  • 270-270: The integration of initChildren within evaluateEach is a good use of the new method to ensure child elements are initialized. This change is logically sound and improves modularity by reusing the initChildren method.

lib/entity.js Show resolved Hide resolved
lib/entity.js Show resolved Hide resolved
lib/entity.js Show resolved Hide resolved
lib/entity.js Show resolved Hide resolved
Copy link

🚀 PR was released in v1.0.1 🚀

3 similar comments
Copy link

🚀 PR was released in v1.0.1 🚀

Copy link

🚀 PR was released in v1.0.1 🚀

Copy link

🚀 PR was released in v1.0.1 🚀

@github-actions github-actions bot added the released This has been released in npm label Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released This has been released in npm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant