Skip to content

Commit a788d34

Browse files
authored
V3.5.1 (#610)
* #600 - added `isDestroyed` property, opts and selectedDates now will have empty values after calendar is destroyed * #600 - added docs for `isDestroyed` * #600 - bupm version, added logs * fixed log
1 parent 1a54ee2 commit a788d34

13 files changed

+72
-16
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
### v3.5.1
4+
* improved `destroy()` behavior - added `isDestroyed` property, `opts` and `selectedDates` will still have empty values, instead of `null`, even after AirDatepicker has been destroyed [#600](https://github.com/t1m0n/air-datepicker/issues/600)
5+
36
### v3.5.0
47
* added `fixedHeight` option, allows you to have equal weeks number in every month
58
* added method `disableDate`, allows you to disabled one or multiple dates with datepicker API

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ new AirDatepicker('#el' [, options]);
2424

2525
## Recent updates
2626

27+
### v3.5.1
28+
* improved `destroy()` behavior - added `isDestroyed` property, `opts` and `selectedDates` will still have empty values, instead of `null`, even after AirDatepicker has been destroyed [#600](https://github.com/t1m0n/air-datepicker/issues/600)
29+
2730
### v3.5.0
2831
* added `fixedHeight` option, allows you to have equal weeks number in every month
2932
* added method `disableDate`, allows you to disabled one or multiple dates with datepicker API

dist/README.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,23 @@ new AirDatepicker('#el' [, options]);
2424

2525
## Recent updates
2626

27+
### v3.5.1
28+
* improved `destroy()` behavior - added `isDestroyed` property, `opts` and `selectedDates` will still have empty values, instead of `null`, even after AirDatepicker has been destroyed [#600](https://github.com/t1m0n/air-datepicker/issues/600)
29+
2730
### v3.5.0
2831
* added `fixedHeight` option, allows you to have equal weeks number in every month
2932
* added method `disableDate`, allows you to disabled one or multiple dates with datepicker API
3033
* added prop `disabledDates` - it is a Set which holds all disabled dates
3134
* added possibility to pass `{silent: true}` to `update` and `setCurrentView` methods, [#583](https://github.com/t1m0n/air-datepicker/issues/568)
32-
* changed `update` method - now if you pass `selectedDates` here then calendar will keep selected only those dates
33-
* fixed localization generation
35+
* changed `update` method - now if you pass `selectedDates` then calendar will keep selected only those dates
3436
* fixed selecting time on same date when `range: true`, [#568](https://github.com/t1m0n/air-datepicker/issues/568)
3537
* fixed date conversion to local date when using strings, e.g `selectDate('2024-03-05')` [#589](https://github.com/t1m0n/air-datepicker/issues/589)
38+
* fixed localization generation, thanks to [hreyeslo](https://github.com/hreyeslo) in [#524](https://github.com/t1m0n/air-datepicker/pull/524)
39+
* fixed type definition for `clear` method, thanks to [ahmetzambak](https://github.com/ahmetzambak) in [#591](https://github.com/t1m0n/air-datepicker/pull/591)
40+
* fixed German translation for "clear", thanks to [pbek](https://github.com/pbek) in [#582](https://github.com/t1m0n/air-datepicker/pull/582)
41+
* added Slovenian locale, thanks to [carliblaz](https://github.com/carliblaz) in [#569](https://github.com/t1m0n/air-datepicker/pull/569)
42+
* added Basque locale, thanks to [ikerib](https://github.com/ikerib) in [#529](https://github.com/t1m0n/air-datepicker/pull/529)
43+
* added Norwegian locale, thanks to [MortenSpjotvoll](https://github.com/MortenSpjotvoll) in [#521](https://github.com/t1m0n/air-datepicker/pull/521)
3644

3745
### v3.4.0
3846
* added new options `onFocus` and `onBeforeSelect` grant you more control over range selection behaviour and more [#526](https://github.com/t1m0n/air-datepicker/issues/526)

dist/air-datepicker.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ declare class AirDatepicker<E extends HTMLElement = HTMLInputElement> {
149149
focusDate: Date | false
150150
visible: boolean
151151
disabledDates: Set<string>
152+
isDestroyed: boolean;
152153
}
153154

154155

dist/air-datepicker.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "air-datepicker",
3-
"version": "3.5.0",
3+
"version": "3.5.1",
44
"scripts": {
5-
"dev": "set NODE_ENV=development&& webpack",
6-
"dev:serve": "npm run browser&& set NODE_ENV=development&& webpack serve",
7-
"prod": "set NODE_ENV=production&& webpack",
5+
"dev": "cross-env NODE_ENV=development webpack",
6+
"dev:serve": "cross-env NODE_ENV=development webpack serve",
7+
"prod": "cross-env NODE_ENV=production webpack",
88
"browser": "open-cli http://localhost:8080 -- 'chrome' ",
99
"build": "node scripts/build.js",
1010
"lint-js": "eslint --fix ./src/*.js",
@@ -26,6 +26,7 @@
2626
"babel-eslint": "^10.1.0",
2727
"babel-loader": "^8.1.0",
2828
"chalk": "^4.1.1",
29+
"cross-env": "^7.0.3",
2930
"css-loader": "^3.5.3",
3031
"ejs": "^3.1.6",
3132
"eslint": "^7.32.0",

docs/locales/en.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -265,5 +265,6 @@ export default {
265265
apiGetViewDates: 'Returns all dates that should be currently displayed in calendar.',
266266
apiDisableDate: 'Disables one or multiple dates.',
267267
apiEnabledDate: 'Enables dates previously disabled.',
268-
apiDisabledDates: 'Set of disabled dates'
268+
apiDisabledDates: 'Set of disabled dates',
269+
apiIsDestroyed: 'If {trueField} then calendar has been destroyed with destroy() method'
269270
};

docs/locales/ru.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -265,5 +265,6 @@ export default {
265265
apiGetViewDates: 'Возвращает все даты, которые должны быть отображены в календаре.',
266266
apiDisableDate: 'Деактивирует одну или несколько дат.',
267267
apiEnabledDate: 'Активирует даты, которые ранее были деактивированы.',
268-
apiDisabledDates: 'Set, где хранятся все деактивированные даты'
268+
apiDisabledDates: 'Set, где хранятся все деактивированные даты',
269+
apiIsDestroyed: 'Если {trueField}, значит календарь был уничтожен с помощью destroy()'
269270
};

docs/pages/methods.js

+3
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ function Methods({} = {}) {
223223
<Param name={'disabledDates'} type={'Set<string>'}>
224224
<Paragraph id={'apiDisabledDates'} />
225225
</Param>
226+
<Param name={'isDestroyed'} type={'boolean'}>
227+
<Paragraph id={'apiIsDestroyed'} values={{trueField}} />
228+
</Param>
226229
</Param.List>
227230
</Section>
228231
</main>

package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "air-datepicker",
3-
"version": "3.5.0",
3+
"version": "3.5.1",
44
"scripts": {
5-
"dev": "set NODE_ENV=development&& webpack",
6-
"dev:serve": "npm run browser&& set NODE_ENV=development&& webpack serve",
7-
"prod": "set NODE_ENV=production&& webpack",
5+
"dev": "cross-env NODE_ENV=development webpack",
6+
"dev:serve": "cross-env NODE_ENV=development webpack serve",
7+
"prod": "cross-env NODE_ENV=production webpack",
88
"browser": "open-cli http://localhost:8080 -- 'chrome' ",
99
"build": "node scripts/build.js",
1010
"lint-js": "eslint --fix ./src/*.js",
@@ -26,6 +26,7 @@
2626
"babel-eslint": "^10.1.0",
2727
"babel-loader": "^8.1.0",
2828
"chalk": "^4.1.1",
29+
"cross-env": "^7.0.3",
2930
"css-loader": "^3.5.3",
3031
"ejs": "^3.1.6",
3132
"eslint": "^7.32.0",

src/datepicker.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ declare class AirDatepicker<E extends HTMLElement = HTMLInputElement> {
149149
focusDate: Date | false
150150
visible: boolean
151151
disabledDates: Set<string>
152+
isDestroyed: boolean;
152153
}
153154

154155

src/datepicker.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ let $datepickersContainer = '',
3535

3636
export default class Datepicker {
3737
static defaults = defaults
38-
static version = '3.5.0'
38+
static version = '3.5.1'
3939
static defaultGlobalContainerId = 'air-datepicker-global-container'
4040
static buildGlobalContainer(id) {
4141
containerBuilt = true;
@@ -74,6 +74,7 @@ export default class Datepicker {
7474
this.currentView = view;
7575
this.selectedDates = [];
7676
this.disabledDates = new Set();
77+
this.isDestroyed = false;
7778
this.views = {};
7879
this.keys = [];
7980
this.rangeDateFrom = '';
@@ -1060,6 +1061,8 @@ export default class Datepicker {
10601061
}
10611062

10621063
destroy = () => {
1064+
if (this.isDestroyed) return;
1065+
10631066
let {showEvent, isMobile} = this.opts;
10641067

10651068
let parent = this.$datepicker.parentNode;
@@ -1082,14 +1085,16 @@ export default class Datepicker {
10821085
this.nav = null;
10831086

10841087
this.$datepicker = null;
1085-
this.opts = null;
1088+
this.opts = {};
10861089
this.$customContainer = null;
10871090

10881091
this.viewDate = null;
10891092
this.focusDate = null;
1090-
this.selectedDates = null;
1093+
this.selectedDates = [];
10911094
this.rangeDateFrom = null;
10921095
this.rangeDateTo = null;
1096+
1097+
this.isDestroyed = true;
10931098
}
10941099

10951100
/**

tests/api.test.js

+28
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,32 @@ describe('API TESTS', () => {
264264
expect(dp.disabledDates.size).toBe(0);
265265
});
266266
});
267+
268+
describe('destory', () => {
269+
it('should destroy AirDatecpiker', () => {
270+
init();
271+
272+
dp.destroy();
273+
274+
expect(dp.isDestroyed).toBe(true);
275+
expect(dp.$datepicker).toBeNull();
276+
});
277+
it('should not throw error when calling destroy after selectDate', () => {
278+
expect(() => {
279+
init();
280+
281+
dp.selectDate(new Date());
282+
dp.destroy();
283+
}).not.toThrow();
284+
});
285+
it('should not throw error when calling destroy multiple times', () => {
286+
expect(() => {
287+
init();
288+
289+
dp.destroy();
290+
dp.destroy();
291+
dp.destroy();
292+
}).not.toThrow();
293+
});
294+
});
267295
});

0 commit comments

Comments
 (0)