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

updates #174

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# EditorConfig is awesome: https://EditorConfig.org

root = true

[*]
trim_trailing_whitespace = false
indent_style = tab
indent_size = 4
end_of_line = lf
charset = utf-8
insert_final_newline = true

[{package*.json,*.yml}]
Expand Down
21 changes: 11 additions & 10 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = {
'@typescript-eslint'
],
rules: {
'indent': ['error', 'tab'],
'indent': [ 'error', 'tab' ],
'key-spacing': [
'warn',
{
Expand All @@ -29,9 +29,9 @@ module.exports = {
align: 'colon',
},
],
'linebreak-style': ['error', 'unix'],
'quotes': ['error', 'single'],
'semi': ['error', 'always'],
'linebreak-style': [ 'error', 'unix' ],
'quotes': [ 'error', 'single' ],
'semi': [ 'error', 'always' ],
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'error',
'no-shadow': [
Expand All @@ -42,9 +42,9 @@ module.exports = {
allow: [],
},
],
'array-bracket-spacing': ['error', 'always'],
'computed-property-spacing': ['error', 'always'],
'object-curly-spacing': ['error', 'always'],
'array-bracket-spacing': [ 'error', 'always' ],
'computed-property-spacing': [ 'error', 'always' ],
'object-curly-spacing': [ 'error', 'always' ],
'space-before-function-paren': [
'error', {
'anonymous': 'always',
Expand Down Expand Up @@ -87,12 +87,13 @@ module.exports = {
'@typescript-eslint/no-explicit-any': 'off',
yoda: 'warn',
},
overrides: [{
files: ['build/**/*.js'],
overrides: [ {
files: [ 'build/**/*.js' ],
rules: {
'no-multi-assign': 0,
'@typescript-eslint/no-this-alias': 0,
'prefer-destructuring': 0,
'new-cap': 0
}
}]
} ]
};
2 changes: 2 additions & 0 deletions .gitconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[core]
hooksPath = .husky/_
14 changes: 8 additions & 6 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,31 @@ jobs:

steps:
- uses: actions/checkout@master
- name: Use Node.js 18.x
- name: Use Node.js 20.x
uses: actions/setup-node@master
with:
node-version: 18.x
node-version: 20.x

- name: npm install
run: npm install

- name: Test
run: npm run test:cov

- name: Coveralls Parallel
- name: Coveralls Start Parallel Build
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
github-token: ${{ secrets.GITHUB_TOKEN }}
debug: true
parallel: true

finish:
needs: test
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
- name: Coveralls Finish Build
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
github-token: ${{ secrets.GITHUB_TOKEN }}
debug: true
parallel-finished: true
3 changes: 3 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
npm run build
# npx lint-staged
npm run test:cov
124 changes: 7 additions & 117 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,107 +391,6 @@ GoneToTheDataBase

```

For sure registering hooks for each defined type is boring, so now we see we have to use Namespaces for Instances.

# Namespaces

By default `define` utilise services of Default Namespace which is always hidden, but always exist. You can lend them using the following technique:

```js

const {
namespaces,
SymbolDefaultNamespace
} = require('mnemonica');

const defaultNamespace = namespaces.get(SymbolDefaultNamespace);

```

**Silly joke, isn't it?** ... sure, you can just use:

```js

const {
defaultNamespace
} = require('mnemonica');

```

And here you can play much more joyfull play with hooks:

```js

defaultNamespace
.registerHook(
'preCreation', preCreationNamespaceCallback);

defaultNamespace
.registerHook(
'postCreation', postCreationNamespaceCallback);

```

So, now all instances crafted from this namespace will call that hooks. The difference between hooks defined using type modificator and hooks defined using namespace is in the following execution order of hooks invocations:

```js

// 1.
namespace.invokeHook('preCreation', // ...

// 2.
type.invokeHook('preCreation', // ...

// 3. instance creation is here

// 4.
type.invokeHook('postCreation', // ...

// 5.
namespace.invokeHook('postCreation', // ...

```

It is important, yes, but not as much as we can expect... because of ... nevermind.

Finally, you can craft your own namespaces:

```js

const {
createNamespace
} = require('mnemonica');

const anotherNamespace =
createNamespace('Another Namespace Name');

```

And there also is one important thing. For example you have to build type modificator with the same name. You can do this, because you can craft as much types modificators collecttions, as you need. Even inside of the same namespace:

```js

const {
createTypesCollection
} = require('mnemonica');

const otherOneTypesCollectionOfDefaultNamespace =
createTypesCollection(defaultNamespace);

const defineOfAnother =
otherOneTypesCollectionOfDefaultNamespace
// another define method -> another ref
.define;

const anotherTypesCollectionOfAnotherNamespace =
createTypesCollection(anotherNamespace);

const defineOfAnotherAnother =
anotherTypesCollectionOfAnotherNamespace
// and another define method -> another ref
.define;

```

And even more. You can use Hooks with Types Collections also (starting from v0.3.1). For doing this just grab referer to collection somewhere, for example:

Expand All @@ -512,33 +411,28 @@ defaultTypes

```

'Pre' hooks for Types Collections invoked after Namespace Hooks invocation, but before Type Hook invocation. 'Post' hooks for Types Collections invoked after Namespace Type Hook invocation, but before Namespace Hooks invocation. So, actually it looks like:
'Pre' hooks for Types Collections invoked before Type Hook invocation. 'Post' hooks for Types Collections invoked after Type Hook invocation. So, actually it looks like:

```js

// 1.
namespace.invokeHook('preCreation', // ...

// 2.
typecollection.invokeHook('preCreation', // ...

// 3.
// 2.
type.invokeHook('preCreation', // ...

// 4. instance creation is here
// 3. instance creation is here

// 5.
// 4.
type.invokeHook('postCreation', // ...

// 6.
// 5.
typecollection.invokeHook('postCreation', // ...

// 7.
namespace.invokeHook('postCreation', // ...

```

As we can see, type hooks are closest one to the type itself. For sure, there can be situations, when you have to register some common hooks, but not for `typecollection` or `namespace`. Assume you have some friendly types, might be from different collections, and you have to register the same hooks definitions for them. And the plase where you wish to do this is the file, other than files you defined that types. There you can use:
As we can see, type hooks are closest one to the type itself. For sure, there can be situations, when you have to register some common hooks, but not for `typecollection`. Assume you have some friendly types, might be from different collections, and you have to register the same hooks definitions for them. And the plase where you wish to do this is the file, other than files you defined that types. There you can use:

# .lookup('TypeName')

Expand Down Expand Up @@ -837,10 +731,6 @@ What you can craft from this instance accordingly with it's defined Type, the sa
## `.__collection__`
Collection of types where `__type__` was defined.

## `.__namespace__`
Namespace where `__collection__` was defined.


# `instance.clone`
Returns cloned instance, with the following condition `instance !== instance.clone`. Cloning includes all the inheritance, with hooks invocations and so on. Therfore cloned instance is not the same as instance, but both made from the same `.__parent__` instance.

Expand Down Expand Up @@ -914,7 +804,7 @@ define('SomeType', function () {}, {}, {
})
```

Also you can override default config options for Types Collection or Namespace. Keep in mind, that TypesCollection options override namespace options. Therefore if you will override namespace options all previously created types collections would not update. For example, after doing so all types that have no own config will fall without any error:
Also you can override default config options for Types Collection. For example, after doing so all types that have no own config will fall without any error:

```js
import {
Expand Down
2 changes: 1 addition & 1 deletion build/api/errors/throwModificationError.js.map

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

2 changes: 1 addition & 1 deletion build/api/types/InstanceCreator.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ConstructorFunction } from '../../types';
declare const InstanceCreatorPrototype: {
getExistentAsyncStack: (existentInstance: import("../utils").asyncStack) => unknown;
postProcessing: (this: any, continuationOf: any) => void;
makeWaiter: (this: any, type: any, then: any) => any;
makeAwaiter: (this: any, type: any, then: any) => any;
addProps: (this: any) => any;
addThen: (this: any, then: any) => void;
invokePreHooks: (this: any) => void;
Expand Down
17 changes: 8 additions & 9 deletions build/api/types/InstanceCreator.js

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

Loading
Loading