Comparing version 1.0.0 to 1.1.0
@@ -39,5 +39,7 @@ const Field = require('./src/initialize') | ||
// Configure encapsulated class. | ||
return Capsulable(Origin, Field()) | ||
let mode = undefined | ||
if(typeof inherit == 'string') mode = inherit | ||
return Capsulable(Origin, Field(), mode) | ||
} | ||
module.exports = Capsulator |
{ | ||
"name": "capsulable", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "A module that helps developers easily encapsulate classes in nodejs.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -10,3 +10,3 @@ ## Capsulable | ||
μΊ‘μλ¬λΈ λͺ¨λμ μλ°μ€ν¬λ¦½νΈ ν΄λμ€μμ μ½κ² μ κ·Όμ νμ κ°λ μ μ¬μ©ν μ μκ² λμ΅λλ€. ν΄λ‘μ λ³μ κ°λ μ ν΅ν΄ μΊ‘μν λ° μλν κ°λ μ ꡬνν©λλ€. | ||
μΊ‘μλ¬λΈ λͺ¨λμ μλ°μ€ν¬λ¦½νΈ ν΄λμ€μμ μ½κ² μ κ·Όμ νμ κ°λ μ μ¬μ©ν μ μκ² λμ΅λλ€. ν΄λ‘μ κ°λ μ ν΅ν΄ μΊ‘μν λ° μλν κ°λ μ ꡬνν©λλ€. | ||
@@ -33,3 +33,3 @@ ## μ€μΉλ°©λ² | ||
Capsulable μ `class` μ `constructor` ν¨μλ₯Ό ν΅ν΄μ λ°μ΄ν° νλλ₯Ό 곡μ ν©λλ€. (μ΄λ μ¦ Capsulable μ΄ μ΅μ’ μ μΌλ‘ νμ μμ ν΄λμ€λ‘ κ΅¬μ± λ¨μ μλ―Έν©λλ€.) μΊ‘μν νκΈΈ μνλ ν΄λμ€λ μ¬μ μ Capsulable μ ν΅ν΄μ coonstructr μμ λ°μ΄ν° νλλ₯Ό μμ λ°μμΌν©λλ€. μμ μ λ¬Έλ²μ ES5λ‘ νκΈ°λλ, Babelμ ν΅ν ES6 λ¬Έλ²μΌλ‘ ꡬνν΄λ λ©λλ€. | ||
Capsulable μ `class` μ `constructor` ν¨μλ₯Ό ν΅ν΄μ λ°μ΄ν° νλλ₯Ό 곡μ ν©λλ€. (μ΄λ μ¦ Capsulable μ΄ μ΅μ’ μ μΌλ‘ νμ μμ ν΄λμ€λ‘ κ΅¬μ± λ¨μ μλ―Έν©λλ€.) μΊ‘μν νκΈΈ μνλ ν΄λμ€λ μ¬μ μ Capsulable μ ν΅ν΄μ constructor μμ λ°μ΄ν° νλλ₯Ό μμ λ°μμΌν©λλ€. μμ μ λ¬Έλ²μ ES5λ‘ νκΈ°λλ, Babelμ ν΅ν ES6 λ¬Έλ²μΌλ‘ ꡬνν΄λ λ©λλ€. | ||
@@ -274,2 +274,22 @@ ### ν΄λμ€ μ μ μμ | ||
## Final Class ꡬν | ||
ν΄λμ€ μνμ μΊ‘μν μ΄ν νμ ν΄λμ€λ₯Ό λ μ΄μ λ§λ€κΈΈ μμΉ μλ κ²½μ° Capsulable ν¨μ μ¬μ©μ 2λ²μ§Έ μΈμλ‘ final λͺ¨λλ₯Ό μ μ©μν΄μΌλ‘μ¨ νμ ν΄λμ€μ λ°μ΄ν° νλλ₯Ό 곡μ νμ§ μλλ‘ ν μ μμ΅λλ€. (ν΄λμ€μ νμμ μμ ν λ§μ§λ λͺ»νλ, λ°μ΄ν° νλκ° κ³΅μ λλ κ²μ λ§μ μλ μμ΅λλ€.) | ||
```js | ||
// index.js | ||
const Capsulable = require('./capsulable') | ||
const A = require('./A') | ||
// 2λ²μ§Έ μΈμλ‘ finalμ μ μΌλ©΄ | ||
// νμν΄λμ€μ λ°μ΄ν° νλλ₯Ό 곡μ νμ§ μμ΅λλ€. | ||
const SharedA = Capsulable(A, 'final') | ||
// μΊ‘μν λ ν΄λμ€λ₯Ό ν΅ν΄μ | ||
// μΈμ€ν΄μ€λ₯Ό μμ±ν μ μμ΅λλ€. | ||
let sharedA = new SharedA() | ||
``` | ||
-------------------------------------- | ||
## μμ λͺ©λ‘ | ||
@@ -288,5 +308,6 @@ | ||
- [x] assert κ°λ³λͺ¨λν νμ¬ μ’ μμ± μμ λ°°μ ꡬν | ||
- [x] final ν΄λμ€ κ΅¬ν | ||
- [ ] final λ³μ ꡬν | ||
- [ ] μΊ‘μν λ ν΄λμ€μ constructor κ°λ³λ³μ μΈμ ꡬν | ||
- [ ] μΊ‘μν λ ν΄λμ€μ constructor κ°λ³λ³μμ νμν΄λμ€ κ³΅μ ꡬν | ||
- [ ] final ν€μλ κΈ°λ₯ ꡬν | ||
-------------------------------------- | ||
@@ -293,0 +314,0 @@ |
@@ -11,3 +11,3 @@ ## Capsulable | ||
Encapsulated modules help you use the concept of access limiting in JavaScript classes. Implement the concepts of encapsulation and concealment through the concept of closure variables. | ||
Encapsulated modules help you use the concept of access limiting in JavaScript classes. Implement the concepts of encapsulation and concealment through the concept of closure. | ||
@@ -37,3 +37,3 @@ | ||
Capable shares the data field through the `constructor` function of `class`. (This means that the Capable is ultimately always composed of child classes.) Classes that want to be encapsulated must inherit the data fields from the Coonstructr through the Capsulable in advance. Examples of grammar are marked as ES5, but can be implemented using ES6 via the Babel. | ||
Capable shares the data field through the `constructor` function of `class`. (This means that the Capable is ultimately always composed of child classes.) Classes that want to be encapsulated must inherit the data fields from the constructor through the Capsulable in advance. Examples of grammar are marked as ES5, but can be implemented using ES6 via the Babel. | ||
@@ -273,2 +273,21 @@ ### Example of class definition | ||
## Implement Final Class | ||
If you no longer want to create a derived class after the encapsulation of a class prototype, you can use the Capsulable function to apply final mode as a second factor to avoid sharing derived classes and data fields. (This does not completely block a class from being derived, but can prevent data fields from being shared.) | ||
```js | ||
// index.js | ||
const Capsulable = require('./capsulable') | ||
const A = require('./A') | ||
// If you write final in the second parameter, | ||
// the derived class and the data fields are not shared. | ||
const SharedA = Capsulable(A, 'final') | ||
// Can create instances through encapsulated classes. | ||
let sharedA = new SharedA() | ||
``` | ||
-------------------------------------- | ||
## Worklist | ||
@@ -287,5 +306,6 @@ | ||
- [x] Implement complete exclusion of dependencies by modularizing asset | ||
- [x] Implement final class | ||
- [ ] Implement final variable | ||
- [ ] Implementing the constructor variable variable factor of the encapsulated class | ||
- [ ] Implementing derivative class sharing with constructor variable of encapsulated class | ||
- [ ] Implement final keyword function | ||
-------------------------------------- | ||
@@ -292,0 +312,0 @@ |
@@ -7,3 +7,3 @@ /** | ||
*/ | ||
module.exports = (Origin, Protect)=>{ | ||
module.exports = (Origin, Protect, mode)=>{ | ||
return class Capsulable extends Origin { | ||
@@ -13,2 +13,10 @@ constructor(inherit){ | ||
super(Field) | ||
// When in final mode, | ||
// the data field is | ||
// not passed to the child class. | ||
if(typeof mode == 'string' | ||
&& mode.toLowerCase() == 'final') | ||
return | ||
if(typeof inherit === 'object') | ||
@@ -15,0 +23,0 @@ if(new.target != this.constructor.name) |
@@ -79,2 +79,16 @@ const assert = require('assert') | ||
UnitTest(packB, packC) | ||
// Final mode Test | ||
let FinalClass = Capsulable(A, 'final') | ||
class FailureClass extends FinalClass{ | ||
constructor(inherit){ | ||
let hook = {} | ||
super(hook) | ||
assert(typeof hook['field'] === 'undefined') | ||
// Field(this, hook.field) | ||
// if(inherit) Capsulable(hook, inherit) | ||
} | ||
} | ||
new FailureClass() | ||
} |
50012
312
25
774