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] withKeepUnmounted decorator #433

Closed
wants to merge 5 commits into from

Conversation

antoine4livre
Copy link
Contributor

@antoine4livre antoine4livre commented Apr 24, 2024

πŸ”— Linked issue

#192

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Try in the playground

import { Base, withKeepUnmounted } from '@studiometa/js-toolkit';

export default class UnmountedComponent extends withKeepUnmounted(Base) {
  static config = {
    name: 'UnmountedComponent',
    log: true,
  };

  mounted() {
    this.$log('Enabled and mounted.');
  }
}
import { Base, createApp } from '@studiometa/js-toolkit';
import UnmountedComponent from './UnmountedComponent.js';

class App extends Base {
  static config = {
    name: 'App',
    components: {
      UnmountedComponent,
    },
    refs: ['btn'],
  };

  onBtnClick() {
    // Set the enabled option to `true` will mount the component
    this.$children.UnmountedComponent[0].$options.enabled = true;
  }
}

createApp(App);

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have added tests (if possible).
  • I have updated the documentation accordingly.
  • I have updated the changelog.

@antoine4livre antoine4livre self-assigned this Apr 24, 2024
@antoine4livre antoine4livre added the enhancement New feature or request label Apr 24, 2024
Copy link

github-actions bot commented Apr 24, 2024

Export Size

@studiometa/js-toolkit

Name Size Diff
withKeepUnmounted 282 B +282 B (+100.00%) πŸ”Ί
DECORATORS 6.37 kB +98 B (+1.56%) πŸ”Ί
FRAMEWORK 11.58 kB +101 B (+0.88%) πŸ”Ί
ALL 16.48 kB +112 B (+0.68%) πŸ”Ί
Unchanged

@studiometa/js-toolkit

Name Size Diff
addClass 226 B -
addStyle 238 B -
animate 2.71 kB -
Base 7.16 kB -
boundingRectToCircle 154 B -
clamp 67 B -
clamp01 87 B -
collideCircleCircle 99 B -
collideCircleRect 159 B -
collidePointCircle 112 B -
collidePointRect 103 B -
collideRectRect 99 B -
createApp 380 B -
createEaseInOut 116 B -
createEaseOut 71 B -
createRange 90 B -
damp 78 B -
debounce 92 B -
domScheduler 296 B -
ease 435 B -
easeInCirc 68 B -
easeInCubic 59 B -
easeInExpo 80 B -
easeInOutCirc 141 B -
easeInOutCubic 130 B -
easeInOutExpo 134 B -
easeInOutQuad 128 B -
easeInOutQuart 133 B -
easeInOutQuint 152 B -
easeInOutSine 151 B -
easeInQuad 63 B -
easeInQuart 61 B -
easeInQuint 62 B -
easeInSine 77 B -
easeLinear 49 B -
easeOutCirc 115 B -
easeOutCubic 103 B -
easeOutExpo 112 B -
easeOutQuad 103 B -
easeOutQuart 100 B -
easeOutQuint 103 B -
easeOutSine 121 B -
endsWith 88 B -
getAncestorWhere 91 B -
getAncestorWhereUntil 119 B -
getClosestParent 178 B -
getComponentResolver 138 B -
getDirectChildren 183 B -
getInstanceFromElement 90 B -
getOffsetSizes 159 B -
hasWindow 62 B -
HELPERS 1.29 kB -
historyPush 499 B -
historyReplace 503 B -
importOnInteraction 454 B -
importOnMediaQuery 236 B -
importWhenIdle 223 B -
importWhenPrefersMotion 275 B -
importWhenVisible 472 B -
inertiaFinalValue 142 B -
isArray 70 B -
isBoolean 78 B -
isDefined 86 B -
isDev 72 B -
isDirectChild 212 B -
isEmpty 207 B -
isEmptyString 93 B -
isFunction 72 B -
isNull 72 B -
isNumber 84 B -
isObject 105 B -
isString 86 B -
keyCodes 100 B -
lerp 57 B -
map 71 B -
matrix 106 B -
mean 91 B -
memoize 189 B -
nextFrame 162 B -
nextMicrotask 111 B -
nextTick 134 B -
noop 39 B -
noopValue 49 B -
objectToURLSearchParams 302 B -
Queue 226 B -
randomInt 80 B -
randomItem 232 B -
removeClass 222 B -
removeStyle 238 B -
round 56 B -
saveActiveElement 56 B -
scrollTo 1.91 kB -
SERVICES 3.21 kB -
SmartQueue 411 B -
startsWith 87 B -
throttle 101 B -
toggleClass 225 B -
transform 321 B -
transition 916 B -
trapFocus 366 B -
tween 1.34 kB -
untrapFocus 45 B -
useDrag 1.61 kB -
useKey 630 B -
useLoad 373 B -
usePointer 841 B -
useRaf 682 B -
useResize 692 B -
useScheduler 290 B -
useScroll 800 B -
useService 254 B -
UTILS 6.67 kB -
wait 79 B -
withBreakpointManager 1.1 kB -
withBreakpointObserver 1.29 kB -
withDrag 1.76 kB -
withExtraConfig 135 B -
withFreezedOptions 140 B -
withIntersectionObserver 285 B -
withLeadingCharacters 88 B -
withLeadingSlash 107 B -
withMountOnMediaQuery 338 B -
withMountWhenInView 331 B -
withMountWhenPrefersMotion 370 B -
withName 81 B -
withoutLeadingCharacters 86 B -
withoutLeadingCharactersRecursive 124 B -
withoutLeadingSlash 93 B -
withoutTrailingCharacters 98 B -
withoutTrailingCharactersRecursive 129 B -
withoutTrailingSlash 103 B -
withRelativePointer 997 B -
withResponsiveOptions 1.89 kB -
withScrolledInView 1.88 kB -
withTrailingCharacters 96 B -
withTrailingSlash 120 B -

@antoine4livre
Copy link
Contributor Author

@titouanmathis I need help to improve my tests...

They work if they are launched separately but not during the CI...

βœ… npm run test -- withKeepUnmounted
πŸ”΄ nom run test

import { Base, createApp, withKeepUnmounted } from '@studiometa/js-toolkit';
import { h } from '#test-utils';

function initApp(
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Return the needed values instead of passing a callback

async function initApp(options?) {
  const div = h('div');
  // ...
  
  const app = await createApp(App, div);

  return { app, div };
}

it('should work', async () => {
  const { app } = await initApp();
  expect(app.$isMounted).toBe(true);
});

@titouanmathis titouanmathis force-pushed the feature/withKeepUnmounted-decorator branch from 413b3ed to a93ce24 Compare June 24, 2024 07:54
Copy link

codecov bot commented Jun 24, 2024

Codecov Report

All modified and coverable lines are covered by tests βœ…

Project coverage is 100.00%. Comparing base (ca62b28) to head (d5e7f37).
Report is 317 commits behind head on develop.

Additional details and impacted files
@@            Coverage Diff            @@
##           develop      #433   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          126       127    +1     
  Lines         4012      4057   +45     
=========================================
+ Hits          4012      4057   +45     
Flag Coverage Ξ”
unittests 100.00% <100.00%> (ΓΈ)

Flags with carried forward coverage won't be shown. Click here to find out more.

β˜” View full report in Codecov by Sentry.
πŸ“’ Have feedback on the report? Share it here.

@titouanmathis
Copy link
Contributor

This will be addressed more globally by #565, closing for now.

@titouanmathis titouanmathis deleted the feature/withKeepUnmounted-decorator branch January 16, 2025 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants