Skip to content

Commit

Permalink
Merge tag '3.0.0-beta.0' into develop
Browse files Browse the repository at this point in the history
v3.0.0-beta.0
  • Loading branch information
titouanmathis committed Nov 16, 2024
2 parents 3c8612d + e9ebe6c commit f4eccd3
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. The format

## [Unreleased]

## [v3.0.0-beta.0](https://github.com/studiometa/js-toolkit/compare/3.0.0-alpha.12..3.0.0-beta.0) (2024-11-16)

### Changed

- Refactor services to classes ([#535](https://github.com/studiometa/js-toolkit/pull/535), [#537](https://github.com/studiometa/js-toolkit/pull/537))
Expand All @@ -12,6 +14,10 @@ All notable changes to this project will be documented in this file. The format

- **useDrag:** prevent drop when not dragging ([#538](https://github.com/studiometa/js-toolkit/issues/538), [#539](https://github.com/studiometa/js-toolkit/pull/539), [63ba2350](https://github.com/studiometa/js-toolkit/commit/63ba2350))

### Removed

- ⚠️ Remove the `useService` export in favor of the `AbstractService` class ([#535](https://github.com/studiometa/js-toolkit/pull/535))

## [v3.0.0-alpha.12](https://github.com/studiometa/js-toolkit/compare/3.0.0-alpha.11..3.0.0-alpha.12) (2024-11-15)

### Fixed
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@studiometa/js-toolkit-workspace",
"version": "3.0.0-alpha.12",
"version": "3.0.0-beta.0",
"private": true,
"type": "module",
"workspaces": [
Expand Down
2 changes: 1 addition & 1 deletion packages/demo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@studiometa/js-toolkit-demo",
"version": "3.0.0-alpha.12",
"version": "3.0.0-beta.0",
"private": true,
"type": "module",
"scripts": {
Expand Down
44 changes: 44 additions & 0 deletions packages/docs/guide/migration/v2-to-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,47 @@ This is considered a breaking change for the following reason:
- The `Base` class no longer extends the `EventTarget` class
- Custom event emitted might conflict with native events
## The `useService` export has been deleted
The services implementation have been refactored as classes instead of the previous functional style. The `useService` function that could be used to create additional services has been removed in favor of the `AbstractService` class.
::: code-group
```js [v2]
import { useService } from '@studiometa/js-tookit';

export function useCustomService() {
const { add, remove, has, get } = useService({
props: {},
init() {},
kill() {},
});

return {
add,
remove,
has,
get,
props: () => props,
};
}
```
```js [v3]
import { AbstractService } from '@studiometa/js-tookit';

class CustomService extends AbstractService {
props = {};

init() {}

kill() {}
}

export function useCustomService() {
return CustomService.getInstance();
}
```
:::
2 changes: 1 addition & 1 deletion packages/docs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@studiometa/js-toolkit-docs",
"version": "3.0.0-alpha.12",
"version": "3.0.0-beta.0",
"type": "module",
"private": true,
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/js-toolkit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@studiometa/js-toolkit",
"version": "3.0.0-alpha.12",
"version": "3.0.0-beta.0",
"description": "A set of useful little bits of JavaScript to boost your project! 🚀",
"publishConfig": {
"access": "public"
Expand Down
50 changes: 44 additions & 6 deletions packages/tests/Base/Base.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,35 @@ import { Base, BaseConfig, BaseProps, getInstanceFromElement } from '@studiometa
import { ChildrenManager, OptionsManager, RefsManager } from '#private/Base/managers/index.js';
import { h } from '#test-utils';

let mockedIsDev = true;

vi.mock(import('#private/utils/is.js'), async (importOriginal) => {
const mod = await importOriginal();
return {
...mod,
get isDev() {
return mockedIsDev;
},
};
});

function mockIsDev(value: boolean) {
const prev = mockedIsDev;
mockedIsDev = value;

return () => {
mockedIsDev = prev;
};
}

async function getContext() {
class Foo<T extends BaseProps = BaseProps> extends Base<T> {
static config: BaseConfig = {
name: 'Foo',
};
}
const element = h('div');
const foo = new Foo(element)
const foo = new Foo(element);
await foo.$mount();

return { Foo, element, foo };
Expand All @@ -23,7 +44,7 @@ describe('The abstract Base class', () => {
}).toThrow();
});

it('should throw an error when extended without proper configuration', () => {
it('should throw an error when extended without proper configuration in dev mode', () => {
expect(() => {
// @ts-ignore
class Foo extends Base {
Expand All @@ -33,7 +54,7 @@ describe('The abstract Base class', () => {
}).toThrow('The `config.name` property is required.');
});

it('should throw an error if instantiated without a root element.', () => {
it('should throw an error if instantiated without a root element in dev mode', () => {
expect(() => {
class Foo extends Base {
static config = {
Expand All @@ -44,6 +65,20 @@ describe('The abstract Base class', () => {
new Foo();
}).toThrow('The root element must be defined.');
});

it('should fail silently in production mode', () => {
const unmock = mockIsDev(false);

class Foo extends Base {}

const foo = new Foo(h('div'));
expect(foo.$id).toBeUndefined();

const foo2 = new Foo();
expect(foo2.$id).toBeUndefined();

unmock();
});
});

describe('A Base instance', () => {
Expand Down Expand Up @@ -153,7 +188,7 @@ describe('A Base instance', () => {
const div = h('div', {}, [
h('div', { dataComponent: 'Component' }, [h('div', { dataComponent: 'ChildComponent' })]),
]);
const app = new App(div)
const app = new App(div);
await app.$mount();
expect(app.$root).toBe(app);
expect(app.$children.Component[0].$root).toBe(app);
Expand Down Expand Up @@ -226,7 +261,7 @@ describe('A Base instance methods', () => {
};
}

const app = new App(div)
const app = new App(div);
await app.$mount();
expect(app.$children.Bar).toHaveLength(2);
expect(app.$children.Bar[0].$isMounted).toBe(true);
Expand Down Expand Up @@ -491,7 +526,9 @@ describe('A Base instance config', () => {
const { Foo } = await getContext();
Foo.config.debug = true;

globalThis.__DEV__ = true;
const devModeSpy = vi.spyOn(globalThis, '__DEV__', 'get');
devModeSpy.mockImplementation(() => true);

process.env.NODE_ENV = 'development';
const spy = vi.spyOn(window.console, 'log');
spy.mockImplementation(() => true);
Expand All @@ -500,6 +537,7 @@ describe('A Base instance config', () => {
expect(args[0].startsWith('[debug] [Foo')).toBe(true);
}
spy.mockRestore();
devModeSpy.mockRestore();
process.env.NODE_ENV = 'test';
});
});
2 changes: 1 addition & 1 deletion packages/tests/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@studiometa/js-toolkit-tests",
"version": "3.0.0-alpha.12",
"version": "3.0.0-beta.0",
"private": true,
"type": "module",
"scripts": {
Expand Down

0 comments on commit f4eccd3

Please sign in to comment.