js-mvc-framework
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -6,2 +6,3 @@ import { DET } from '/dependencies/mvc-framework.js' | ||
export default function DETObjectInstantiation() { | ||
console.log('DET Object Instantiation') | ||
const object = new DET({ | ||
@@ -22,7 +23,3 @@ aaa: 111, | ||
}) | ||
object.addEventListener("assign", objectAssign) | ||
object.assign({ aaa: 111111 }) | ||
console.log(object.inspect()) | ||
object.removeEventListener("assign", objectAssign) | ||
object.assign({ aaa: 111111111 }) | ||
} |
@@ -1,46 +0,10 @@ | ||
import { DET } from '/dependencies/mvc-framework.js' | ||
function objectAssign($event) { | ||
console.log($event) | ||
} | ||
function objectFreeze($event) { | ||
// console.log($event.type, $event.detail.target) | ||
} | ||
import objectAssign from './assign/index.js' | ||
import defineProperties from './defineProperties/index.js' | ||
import defineProperty from './defineProperty/index.js' | ||
export default function DETObjectVentilation() { | ||
const object = new DET({ | ||
aaa: { | ||
bbb: { | ||
ccc: { | ||
ddd: 444 | ||
} | ||
} | ||
} | ||
}) | ||
object.aaa.bbb.addEventListener('assign', objectAssign) | ||
object.assign({ | ||
aaa: { | ||
bbb: { | ||
ccc: { | ||
ddd: 444444 | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
// export default function DETObjectVentilation() { | ||
// const object = new DET({ | ||
// aaa: 111, | ||
// bbb: { | ||
// ccc: "333", | ||
// ddd: true, | ||
// }, | ||
// }) | ||
// // console.log(object.content) | ||
// object.bbb.addEventListener('assign', objectAssign) | ||
// object.addEventListener('assign', objectAssign) | ||
// object.assign({ | ||
// bbb: { | ||
// ccc: "333333", | ||
// ddd: false | ||
// } | ||
// }) | ||
// } | ||
console.log('DET Object Ventilation') | ||
// objectAssign() | ||
// defineProperties() | ||
defineProperty() | ||
} |
@@ -16,7 +16,9 @@ import DynamicEventTarget from '../index.js' | ||
const { | ||
$eventTarget, $root, $rootAlias, $type, $proxy | ||
$eventTarget, | ||
$root, $rootAlias, | ||
$type, $proxy, | ||
} = this.#aliases | ||
return function get($target, $property, $receiver) { | ||
// 1. Root Alias | ||
if($property === $rootAlias) return $root | ||
if($property === $rootAlias) return this | ||
if( | ||
@@ -23,0 +25,0 @@ // 2. Event Target Class Instance Methods |
@@ -13,3 +13,3 @@ import { isDirectInstanceOf } from '../../Coutil/index.js' | ||
if(isDirectInstanceOf( | ||
$sourcePropVal, [Array, Object, Map] | ||
$sourcePropVal, [Object, Array/*, Map*/] | ||
)) { | ||
@@ -16,0 +16,0 @@ value = new DynamicEventTarget(value, { |
@@ -15,3 +15,3 @@ import { isDirectInstanceOf } from '../../Coutil/index.js' | ||
if(isDirectInstanceOf( | ||
$element, [Array, Object, Map] | ||
$element, [Object, Array/*, Map*/] | ||
)) { | ||
@@ -18,0 +18,0 @@ $element = new DynamicEventTarget($element, { |
@@ -19,3 +19,3 @@ import { isDirectInstanceOf } from '../../Coutil/index.js' | ||
if(isDirectInstanceOf( | ||
element, [Array, Object, Map] | ||
element, [Object, Array/*, Map*/] | ||
)) { | ||
@@ -22,0 +22,0 @@ element = new DynamicEventTarget(element, { |
@@ -6,3 +6,9 @@ import { isDirectInstanceOf } from '../../Coutil/index.js' | ||
) { | ||
const { $eventTarget, $root, $rootAlias, $path, $basename } = $aliases | ||
const { | ||
$eventTarget, | ||
$root, | ||
$rootAlias, | ||
$basename, | ||
$path, | ||
} = $aliases | ||
const { merge } = $options | ||
@@ -13,4 +19,6 @@ return Object.defineProperty( | ||
const sources = [...arguments] | ||
// Iterate Sources | ||
iterateSources: | ||
for(let $source of sources) { | ||
// Iterate Source Props | ||
iterateSourceProps: | ||
@@ -20,14 +28,18 @@ for(let [ | ||
] of Object.entries($source)) { | ||
// Assign Root DET Property | ||
if( | ||
isDirectInstanceOf( | ||
$sourcePropVal, [Array, Object, Map] | ||
$sourcePropVal, [Object, Array/*, Map*/] | ||
) | ||
) { | ||
// Assign Existent Root DET Property | ||
if( | ||
merge === true && | ||
$root[$sourcePropKey] | ||
.constructor.name === 'bound DynamicEventTarget' | ||
?.constructor.name === 'bound DynamicEventTarget' | ||
) { | ||
$root[$sourcePropKey].assign($sourcePropVal) | ||
} else { | ||
} else | ||
// Assign Non-Existent Root DET Property | ||
{ | ||
const basename = $sourcePropKey | ||
@@ -38,13 +50,64 @@ const path = ( | ||
: $sourcePropKey | ||
const detObject = new DynamicEventTarget( | ||
$sourcePropVal, { | ||
$rootAlias, | ||
$path: path, | ||
$basename: basename, | ||
$parent: $eventTarget | ||
} | ||
) | ||
detObject.addEventListener( | ||
'assignSourceProperty', ($event) => { | ||
const assignSourcePropertyEventData = { | ||
key: $event.detail.key, | ||
val: $event.detail.val, | ||
source: $event.detail.source, | ||
path: $event.path, | ||
basename: $event.basename, | ||
} | ||
$trap.createEvent( | ||
$eventTarget, | ||
'assignSourceProperty', | ||
assignSourcePropertyEventData, | ||
$root, | ||
) | ||
} | ||
) | ||
detObject.addEventListener( | ||
'assignSource', ($event) => { | ||
const assignSourceEventData = { | ||
source: $event.detail.source, | ||
path: $event.path, | ||
basename: $event.basename, | ||
} | ||
$trap.createEvent( | ||
$eventTarget, | ||
'assignSource', | ||
assignSourceEventData, | ||
$root | ||
) | ||
} | ||
) | ||
detObject.addEventListener( | ||
'assign', ($event) => { | ||
const assignEventData = { | ||
sources: $event.detail.sources, | ||
path: $event.path, | ||
basename: $event.basename, | ||
} | ||
$trap.createEvent( | ||
$eventTarget, | ||
'assign', | ||
assignEventData, | ||
$root, | ||
) | ||
} | ||
) | ||
Object.assign($root, { | ||
[$sourcePropKey]: new DynamicEventTarget( | ||
$sourcePropVal, { | ||
$rootAlias, | ||
$path: path, | ||
$basename: basename, | ||
} | ||
) | ||
[$sourcePropKey]: detObject | ||
}) | ||
} | ||
} else { | ||
} else | ||
// Assign Root Property | ||
{ | ||
Object.assign($root, { | ||
@@ -54,34 +117,43 @@ [$sourcePropKey]: $sourcePropVal | ||
} | ||
// Assign Source Property Event Data | ||
const assignSourcePropertyEventData = { | ||
key: $sourcePropKey, | ||
val: $sourcePropVal, | ||
source: $source, | ||
path: $path, | ||
basename: $basename, | ||
} | ||
// Assign Source Property Event | ||
$trap.createEvent( | ||
$eventTarget, | ||
'assignSourceProperty', | ||
{ | ||
key: $sourcePropKey, | ||
val: $sourcePropVal, | ||
source: $source, | ||
path: $path, | ||
basename: $basename, | ||
}, | ||
assignSourcePropertyEventData, | ||
$root, | ||
) | ||
} | ||
// Assign Source Event Data | ||
const assignSourceEventData = { | ||
source: $source, | ||
path: $path, | ||
basename: $basename, | ||
} | ||
// Assign Source Event | ||
$trap.createEvent( | ||
$eventTarget, | ||
'assignSource', | ||
{ | ||
source: $source, | ||
path: $path, | ||
basename: $basename, | ||
}, | ||
assignSourceEventData, | ||
$root | ||
) | ||
} | ||
// Assign Event Data | ||
const assignEventData = { | ||
sources, | ||
path: $path, | ||
basename: $basename, | ||
} | ||
// Assign Event | ||
$trap.createEvent( | ||
$eventTarget, | ||
'assign', | ||
{ | ||
sources, | ||
path: $path, | ||
basename: $basename, | ||
}, | ||
assignEventData, | ||
$root, | ||
@@ -88,0 +160,0 @@ ) |
@@ -6,4 +6,37 @@ import { typeOf, isDirectInstanceOf } from '../../Coutil/index.js' | ||
) { | ||
const { $eventTarget, $root, $rootAlias, $path, $basename } = $aliases | ||
const { | ||
$eventTarget, | ||
$root, | ||
$rootAlias, | ||
$basename, | ||
$path, | ||
} = $aliases | ||
const { descriptorValueMerge, descriptorTree } = $options | ||
function defineProperty($event) { | ||
const definePropertyEventData = { | ||
prop: $event.detail.prop, | ||
descriptor: $event.detail.descriptor, | ||
path: $event.path, | ||
basename: $event.basename, | ||
} | ||
$trap.createEvent( | ||
$eventTarget, | ||
'defineProperty', | ||
definePropertyEventData, | ||
$root, | ||
) | ||
} | ||
function defineProperties($event) { | ||
const definePropertiesEventData = { | ||
descriptors: $event.detail.descriptors, | ||
path: $event.path, | ||
basename: $event.basename, | ||
} | ||
$trap.createEvent( | ||
$eventTarget, | ||
'defineProperties', | ||
definePropertiesEventData, | ||
$root, | ||
) | ||
} | ||
return Object.defineProperty( | ||
@@ -13,57 +46,21 @@ $trap, $trapPropertyName, { | ||
const $propertyDescriptors = arguments[0] | ||
// Iterate Property Descriptors | ||
iteratePropertyDescriptors: | ||
for(const [ | ||
$propertyKey, $propertyDescriptor | ||
] of Object.entries($propertyDescriptors)) { | ||
if(isDirectInstanceOf( | ||
$propertyDescriptor.value, [Array, Object, Map] | ||
)) { | ||
const rootPropertyDescriptor = Object.getOwnPropertyDescriptor( | ||
$root, $propertyKey | ||
) || {} | ||
// Descriptor Value Merge | ||
if( | ||
descriptorValueMerge === true && | ||
rootPropertyDescriptor.value instanceof DynamicEventTarget | ||
) { | ||
$propertyDescriptor.value = rootPropertyDescriptor.value | ||
} else { | ||
$propertyDescriptor.value = new DynamicEventTarget( | ||
$propertyDescriptor.value, { | ||
rootAlias: $rootAlias, | ||
} | ||
) | ||
} | ||
} | ||
Object.defineProperties($root, { | ||
[$propertyKey]: $propertyDescriptor | ||
}) | ||
// Descriptor Tree | ||
if( | ||
descriptorTree === true && | ||
$propertyDescriptor.defineProperties !== undefined | ||
) { | ||
$propertyDescriptor.value.defineProperties( | ||
$propertyDescriptor.defineProperties | ||
) | ||
} | ||
$trap.createEvent( | ||
$eventTarget, | ||
'defineProperty', | ||
{ | ||
prop: $propertyKey, | ||
descriptor: $propertyDescriptor, | ||
path: $path, | ||
basename: $basename, | ||
}, | ||
$root, | ||
) | ||
// Property Descriptor Value Is Direct Instance Of Array/Object/Map | ||
$trap.defineProperty($propertyKey, $propertyDescriptor) | ||
} | ||
// Define Properties Event Data | ||
const definePropertiesEventData = { | ||
descriptors: $propertyDescriptors, | ||
path: $path, | ||
basename: $basename, | ||
} | ||
// Define Properties Event | ||
$trap.createEvent( | ||
$eventTarget, | ||
'defineProperties', | ||
{ | ||
descriptors: $propertyDescriptors, | ||
path: $path, | ||
basename: $basename, | ||
}, | ||
definePropertiesEventData, | ||
) | ||
@@ -74,2 +71,2 @@ return $root | ||
) | ||
} | ||
} |
@@ -6,50 +6,125 @@ import { typeOf, isDirectInstanceOf } from '../../Coutil/index.js' | ||
) { | ||
const { $eventTarget, $root } = $aliases | ||
const { | ||
$eventTarget, | ||
$root, | ||
$rootAlias, | ||
$basename, | ||
$path, | ||
} = $aliases | ||
const { descriptorValueMerge, descriptorTree } = $options | ||
function defineProperty($event) { | ||
const definePropertyEventData = { | ||
prop: $event.detail.prop, | ||
descriptor: $event.detail.descriptor, | ||
path: $event.path, | ||
basename: $event.basename, | ||
} | ||
$trap.createEvent( | ||
$eventTarget, | ||
'defineProperty', | ||
definePropertyEventData, | ||
$root, | ||
) | ||
} | ||
return Object.defineProperty( | ||
$trap, $trapPropertyName, { | ||
value: function() { | ||
let propertyKey = arguments[0] | ||
let propertyDescriptor = arguments[1] | ||
const propertyKey = arguments[0] | ||
const propertyDescriptor = arguments[1] | ||
// Property Descriptor Value Is Direct Instance Of Array/Object/Map | ||
if(isDirectInstanceOf( | ||
propertyDescriptor.value, [Array, Object, Map] | ||
propertyDescriptor.value, [Object, Array/*, Map*/] | ||
)) { | ||
const rootPropertyDescriptor = Object.getOwnPropertyDescriptor( | ||
$root, $propertyKey | ||
$root, propertyKey | ||
) || {} | ||
// Descriptor Value Merge | ||
// Root Property Descriptor Value Is Existent DET Instance | ||
if( | ||
descriptorValueMerge === true && | ||
rootPropertyDescriptor.value instanceof DynamicEventTarget | ||
rootPropertyDescriptor.value // instanceof DynamicEventTarget | ||
?.constructor.name === 'bound DynamicEventTarget' | ||
) { | ||
propertyDescriptor.value = rootPropertyDescriptor.value | ||
} else { | ||
propertyDescriptor.value = new DynamicEventTarget( | ||
propertyDescriptor.value, { | ||
rootAlias: $rootAlias, | ||
$root[propertyKey].removeEventListener( | ||
'defineProperty', | ||
defineProperty | ||
) | ||
$root[propertyKey].addEventListener( | ||
'defineProperty', | ||
defineProperty | ||
) | ||
// Root Define Properties, Descriptor Tree | ||
if(descriptorTree === true) { | ||
$trap.defineProperty(propertyKey, propertyDescriptor) | ||
} else | ||
// Root Define Properties, No Descriptor Tree | ||
{ | ||
Object.defineProperty( | ||
$root, propertyKey, propertyDescriptor | ||
) | ||
} | ||
} | ||
// Root Property Descriptor Value Is Non-Existent DET Instance | ||
else { | ||
const basename = propertyKey | ||
const path = ( | ||
$path !== null | ||
) ? $path.concat('.', propertyKey) | ||
: propertyKey | ||
const root = ( | ||
typeOf( | ||
propertyDescriptor.value | ||
) === 'object' | ||
) ? {} | ||
: ( | ||
typeOf( | ||
propertyDescriptor.value | ||
) === 'array' | ||
) ? [] | ||
// : typeOf( | ||
// propertyDescriptor.value | ||
// ) === 'map' | ||
// ? new Map() | ||
: {} | ||
const detObject = new DynamicEventTarget( | ||
root, { | ||
$rootAlias, | ||
$path: path, | ||
$basename: basename, | ||
$parent: $eventTarget, | ||
} | ||
) | ||
detObject.addEventListener( | ||
'defineProperty', | ||
defineProperty | ||
) | ||
// Root Define Properties, Descriptor Tree | ||
if(descriptorTree === true) { | ||
detObject.defineProperties( | ||
propertyDescriptor.value | ||
) | ||
$root[propertyKey] = detObject | ||
} else { | ||
Object.defineProperty( | ||
$root, propertyKey, propertyDescriptor | ||
) | ||
} | ||
} | ||
} else { | ||
Object.defineProperty( | ||
$root, propertyKey, propertyDescriptor | ||
) | ||
} | ||
Object.defineProperty($root, propertyKey, propertyDescriptor) | ||
// Descriptor Tree | ||
if( | ||
descriptorTree === true && | ||
propertyDescriptor.defineProperties !== undefined | ||
) { | ||
for(let [ | ||
$subpropertyKey, $subpropertyDescriptor | ||
] of Object.entries(propertyDescriptor.defineProperties)) { | ||
propertyDescriptor.defineProperty($subpropertyKey, $subpropertyDescriptor) | ||
} | ||
// Define Property Event Data | ||
const definePropertyEventData = { | ||
prop: propertyKey, | ||
descriptor: propertyDescriptor, | ||
path: $path, | ||
basename: $basename, | ||
} | ||
// Define Property Event | ||
$trap.createEvent( | ||
$eventTarget, | ||
'defineProperty', | ||
{ | ||
prop: propertyKey, | ||
descriptor: propertyDescriptor, | ||
path: $path, | ||
basename: $basename, | ||
}, | ||
definePropertyEventData, | ||
$root, | ||
) | ||
@@ -56,0 +131,0 @@ return $root |
@@ -17,2 +17,3 @@ import { typeOf } from '../../Coutil/index.js' | ||
#_root | ||
#_parent | ||
#_basename | ||
@@ -37,2 +38,10 @@ #_path | ||
} | ||
get parent() { | ||
if(this.#_parent !== undefined) return this.#_parent | ||
this.#_parent = ( | ||
this.#options.$parent !== undefined | ||
) ? this.#options.$parent | ||
: null | ||
return this.#_parent | ||
} | ||
get basename() { | ||
@@ -58,6 +67,6 @@ if(this.#_basename !== undefined) return this.#_basename | ||
this.#_rootAlias = ( | ||
typeof this.#options.rootAlias === 'string' && | ||
this.#options.rootAlias.length > 0 | ||
) ? this.#options.rootAlias | ||
: 'content' | ||
typeof this.#options.$rootAlias === 'string' && | ||
this.#options.$rootAlias.length > 0 | ||
) ? this.#options.$rootAlias | ||
: Options.rootAlias | ||
return this.#_rootAlias | ||
@@ -144,5 +153,31 @@ } | ||
$basename: this.basename, | ||
$parent: this.parent, | ||
} | ||
return this.#_aliases | ||
} | ||
parse() { | ||
let parsement = ( | ||
this.type === 'object' | ||
) ? {} | ||
: ( | ||
this.type === 'array' | ||
) ? [] | ||
/*: ( | ||
this.type === 'map' | ||
) ? new Map()*/ | ||
: {} | ||
if(this.type !== 'map') { | ||
for(const [$key, $val] of Object.entries(this.#root)) { | ||
if( | ||
$val !== null && | ||
typeof $val === 'object' | ||
) { | ||
parsement[$key] = $val.parse() | ||
} else( | ||
parsement[$key] = $val | ||
) | ||
} | ||
} | ||
return parsement | ||
} | ||
inspect() { | ||
@@ -149,0 +184,0 @@ return JSON.stringify(this.parse(), null, 2) |
{ | ||
"name": "js-mvc-framework", | ||
"author": "Thomas Patrick Welborn", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"type": "module", | ||
@@ -6,0 +6,0 @@ "main": "./development/index.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1212319
238
253
12782
33