Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c147d54

Browse files
committed
Fix not being able to set configuration after disabling function import
1 parent 7aed291 commit c147d54

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

HISTORY.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# History
22

33

4+
# not yet published, version 6.0.2
5+
6+
- Fix not being able to set configuration after disabling function `import`
7+
(regression since v6.0.0).
8+
9+
410
# 2019-06-09, version 6.0.1
511

612
- Fix function reference not published in npm library.

src/core/create.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,17 @@ export function create (factories, config) {
208208
function lazyTyped (...args) {
209209
return math.typed.apply(math.typed, args)
210210
}
211-
math['import'] = importFactory(lazyTyped, load, math, importedFactories)
211+
const internalImport = importFactory(lazyTyped, load, math, importedFactories)
212+
math['import'] = internalImport
212213

213214
// listen for changes in config, import all functions again when changed
215+
// TODO: move this listener into the import function?
214216
math.on('config', () => {
215217
values(importedFactories).forEach(factory => {
216218
if (factory && factory.meta && factory.meta.recreateOnConfigChange) {
217219
// FIXME: only re-create when the current instance is the same as was initially created
218220
// FIXME: delete the functions/constants before importing them again?
219-
math['import'](factory, { override: true })
221+
internalImport(factory, { override: true })
220222
}
221223
})
222224
})
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1+
import assert from 'assert'
2+
import math from '../../../src/bundleAny'
13

24
describe('config', function () {
5+
it('should allow setting config after having overwritten import', () => {
6+
const math2 = math.create()
7+
8+
assert.strictEqual(math2.typeOf(math2.pi), 'number')
9+
10+
math2.import({
11+
import: () => { throw new Error('Function import is disabled') }
12+
}, { override: true })
13+
14+
math2.config({ number: 'BigNumber' })
15+
16+
assert.strictEqual(math2.typeOf(math2.pi), 'BigNumber')
17+
})
18+
319
// TODO: test function config
420
})

0 commit comments

Comments
 (0)