Skip to content

Conversation

ws-rush
Copy link

@ws-rush ws-rush commented Jul 16, 2022

I am so excited, this is my first pull request on github, I dont know typescript, and I wish this pull request accepted

I did this commit to distribute custom directives as packages then use them with petite-vue, I also added example use in README file, thats it:

Use Plugins

You can write custome directive then distrbute it as a pacage, then add it to create vue, like:

<div v-scope="{counter: 0}" v-log="inside petite-vue scope">
  <button @click="counter++">increase</button>
</div>

<script type="module">
  import log from './log'
  import { createApp } from 'peteite-vue'
  createApp().use(log).mount()
</script>

A plugin code similar to vue plugins code:

// inside log.js plugin file
export default {
  install: (app, options) => {
    app.directive('log', ({exp}) => {
      console.log(exp)
    })
  }
}

wusaby-rush and others added 10 commits August 29, 2022 03:03
Some times like in dialogs we need access to root component from child nodes, also it is a way to access root element from `v-scope` . the next snippet from another PR to expose `$el` to scope, but this PR can solve the same problem also

```html
<textarea
  v-scope="{width: $root.offsetWidth, height: $root.offsetHeight}"
  @click="width = $el.offsetWidth; height = $el.offsetHeight;"
>
{{ width }} &times; {{ height }}
</textarea>
```
@sqllyw
Copy link

sqllyw commented Jul 11, 2023

what is the advantage of use() over directive() ? example:

createApp().directive('log',log).mount() vs 
createApp().use(log).mount()

lucafabbian and others added 15 commits November 8, 2023 15:07
   - Replace deprecated vuejs/vue-next with microsoft/vscode repository
   - Fix branch names from wildcards to specific release branches
fix: update commits example to use working API endpoint
  - Add complete Vitest configuration with Happy DOM environment
  - Create 119 tests covering all core modules and directives
  - Achieve 82.84% test coverage across the entire codebase
  - Add tests for app creation, mounting, and lifecycle
  - Test all built-in directives (v-bind, v-on, v-model, v-show, v-text, v-html, v-effect)
  - Include comprehensive reactivity and async testing patterns
  - Add error handling and edge case coverage
  - Create integration tests for component-like behavior
  - Add tests for utilities, scheduler, and DOM walking functionality
  - Write comprehensive testing guide with best practices
  - Document common testing patterns and examples
  - Add ES module support with type: module
  - Upgrade Vue dependencies from 3.2.45 to 3.5.21
  - Update dev dependencies to latest stable versions
chore: update dependencies and build configuration to modern standards
ws-rush and others added 26 commits September 23, 2025 20:15
  - Update production CDN URLs from version 1.0.3 to 1.0.5
  - Add comprehensive CDN links section with jsDelivr and unpkg options
  - Provide direct links for both global and ESM builds across CDN providers
  - Use parentNode fallback when parentElement is null
  - Add safety check to prevent runtime errors
  - Handle template tag scenarios in v-for loops
  - Prevents crashes when v-if is used inside template elements
This commit addresses several issues and introduces improvements across the library, primarily focusing on the `v-bind` directive's reactivity and enhancing the test environment's reliability.

**Bug Fixes:**

	- **`ReferenceError: style is not defined` in `src/directives/bind.ts`:** Resolved an issue where the `style` object was not consistently defined, leading to errors in style binding.

**Refactoring & Enhancements:**

	- **`v-bind` Directive (`src/directives/bind.ts`):**
	- Removed `happy-dom`-specific conditional workarounds, restoring the code to its original, idiomatic DOM manipulation logic.
	- **Test Environment (`src/test/setup.ts`):**
	- Implemented a `happy-dom` patch for `Element.prototype.setAttribute`. This patch forces attribute updates (for `id`, `class`, `style`, `title`, `lang`, `dir`) by performing `removeAttribute` before `setAttribute` in the test environment. This ensures reliable test execution without polluting application code.
	- **Directive Integration (`src/directives/index.ts`):**
		- Formalized the inclusion of `ref`, `v-for` (`_for`), and `v-if` (`_if`) directives into `builtInDirectives`.
	- **`v-for` and `v-if` Directives (`src/directives/for.ts`, `src/directives/if.ts`):**
		- Corrected `evaluate` calls to consistently pass the `el` argument, ensuring proper evaluation context.
	- **`v-model` Directive (`src/directives/model.ts`):**
		- Improved behavior for `<select multiple>` elements by ensuring new array instances are created on update.
		- Adjusted checkbox array handling for consistency.
	- **`v-ref` Directive (`src/directives/ref.ts`):**
		- Added fallback logic to use the expression string as the ref name if the evaluated ref value is `undefined`.
	- **`evaluate` and `execute` Functions (`src/eval.ts`):**
		- Refactored `evaluate` for direct `new Function` usage and optimized `execute` with `evalCache`.
	- **`nextTick` Function (`src/scheduler.ts`):**
		- Enhanced `nextTick` to support both callback and Promise-based waiting for job completion.
	- **`createApp` Function (`src/app.ts`):**
		- Added `rootBlocks` and `scope` getters to the app instance.
		- Improved error reporting for invalid selectors.
	- **`walk` Function (`src/walk.ts`):**
		- Updated to reflect changes in `ref` directive handling and `evaluate` context.

 **Chore:**

	- **Dependency Updates:** Updated various development dependencies (`@types/node`, `happy-dom`, `typescript`, `vitest`, `terser`).
	- **Script Changes:** Renamed `test:run` to `test:once` and added a `typecheck` script in `package.json`.
	- **Configuration Update:** Updated `moduleResolution` to `bundler` in `tsconfig.json`.

	This commit significantly improves the stability and maintainability of the library's testing setup while also delivering minor bug fixes and feature enhancements.
The `v-bind` directive was not correctly removing attributes like `id`, `title`, `lang`, and `dir` when their bound values became `null` or `undefined`. Previously, `el.setAttribute(key, value)` would set the attribute's value to the string "null" or "undefined" instead of removing the attribute entirely.

This commit modifies the `setProp` function in `src/directives/bind.ts` to explicitly call `el.removeAttribute(key)` when the value for these specific attributes is `null` or `undefined`.

Additionally, a logical error in `__tests__/directives.test.ts` was corrected. An `expect(div?.hasAttribute("id")).toBe(false);` assertion was incorrectly placed before the `data.id` was set to `undefined`, causing a premature test failure. This assertion has been removed from its incorrect position.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants