Skip to content

Commit

Permalink
Merge pull request #155 from wentout/proto
Browse files Browse the repository at this point in the history
args fix
  • Loading branch information
wentout committed Nov 9, 2023
2 parents f715f86 + 0d6aedd commit 8ee0751
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ exports.lookup = function (TypeNestedPath) {
const types = checkThis(this) ? exports.defaultTypes : this || exports.defaultTypes;
return types.lookup(TypeNestedPath);
};
const apply = function (entity, Constructor, args) {
const apply = function (entity, Constructor, args = []) {
const result = new entity[Constructor.TypeName](...args);
return result;
};
Expand Down
2 changes: 1 addition & 1 deletion 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": "mnemonica",
"version": "0.9.972",
"version": "0.9.973",
"description": "abstract technique that aids information retention : instance inheritance system",
"type": "commonjs",
"main": "./build/index.js",
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const lookup = function (TypeNestedPath) {
return types.lookup(TypeNestedPath);
} as TypeLookup;

export const apply = function <E extends object, T extends object, S extends Proto<E, T>> (entity: E, Constructor: IDEF<T>, args?: unknown[]): {
export const apply = function <E extends object, T extends object, S extends Proto<E, T>> (entity: E, Constructor: IDEF<T>, args: unknown[] = []): {
[key in keyof S]: S[key]
} {
// const result = Constructor.apply(entity, args);
Expand Down
3 changes: 3 additions & 0 deletions test/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const tests = (opts) => {
SubOfSomeADTCTypePre,
SubOfSomeADTCTypePost,
subOfSomeADTCInstanceA,
subOfSomeADTCInstanceANoArgs,
subOfSomeADTCInstanceC,
subOfSomeADTCInstanceB,
anotherNamespace,
Expand Down Expand Up @@ -351,7 +352,9 @@ const tests = (opts) => {

expect(SubOfSomeADTCTypePre.existentInstance).equal(someADTCInstance);
expect(SubOfSomeADTCTypePost.existentInstance).equal(someADTCInstance);
expect(subOfSomeADTCInstanceANoArgs.test).equal(123);
expect(subOfSomeADTCInstanceA.test).equal(123);
expect(subOfSomeADTCInstanceANoArgs.sub_test).equal(321);
expect(subOfSomeADTCInstanceA.sub_test).equal(321);
expect(subOfSomeADTCInstanceA.args).deep.to.equal([ 1, 2, 3 ]);

Expand Down
2 changes: 2 additions & 0 deletions test/hookSamples.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const namespaceFlowCheckerSample = [
'SubOfSomeADTCType',
'SubOfSomeADTCType',
'SubOfSomeADTCType',
'SubOfSomeADTCType',
'SubOfSomeADTCType',
'UserType',
'UserType',
'UserTypePL1',
Expand Down
6 changes: 3 additions & 3 deletions test/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const tests = (opts) => {
assert.equal(8, userTypeHooksInvocations.length);
debugger;
// +2
assert.equal(177, namespaceFlowCheckerInvocations.length);
assert.equal(179, namespaceFlowCheckerInvocations.length);
// +2
assert.equal(169, typesFlowCheckerInvocations.length);
// +1
Expand All @@ -48,10 +48,10 @@ const tests = (opts) => {
// +1
assert.equal(77, typesPostCreationInvocations.length);
// +1
assert.equal(96, namespacePreCreationInvocations.length);
assert.equal(97, namespacePreCreationInvocations.length);
// there are two registered Hooks, that is why
// +2
assert.equal(162, namespacePostCreationInvocations.length);
assert.equal(164, namespacePostCreationInvocations.length);
});
});

Expand Down
2 changes: 2 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ SubOfSomeADTCType.registerHook('postCreation', (opts) => {
});

// debugger;
const subOfSomeADTCInstanceANoArgs = apply(someADTCInstance, SubOfSomeADTCType);
const subOfSomeADTCInstanceA = apply(someADTCInstance, SubOfSomeADTCType, [ 1, 2, 3 ]);

// debugger;
Expand Down Expand Up @@ -608,6 +609,7 @@ describe('Main Test', () => {
someADTCInstance,
SubOfSomeADTCTypePre,
SubOfSomeADTCTypePost,
subOfSomeADTCInstanceANoArgs,
subOfSomeADTCInstanceA,
subOfSomeADTCInstanceC,
subOfSomeADTCInstanceB,
Expand Down

0 comments on commit 8ee0751

Please sign in to comment.