Website Structure
This commit is contained in:
parent
62812f2090
commit
71f0676a62
22365 changed files with 4265753 additions and 791 deletions
8
Frontend-Learner/node_modules/on-change/source/smart-clone/clone/clone-array.js
generated
vendored
Normal file
8
Frontend-Learner/node_modules/on-change/source/smart-clone/clone/clone-array.js
generated
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import {HANDLED_ARRAY_METHODS} from '../methods/array.js';
|
||||
import CloneObject from './clone-object.js';
|
||||
|
||||
export default class CloneArray extends CloneObject {
|
||||
static isHandledMethod(name) {
|
||||
return HANDLED_ARRAY_METHODS.has(name);
|
||||
}
|
||||
}
|
||||
11
Frontend-Learner/node_modules/on-change/source/smart-clone/clone/clone-date.js
generated
vendored
Normal file
11
Frontend-Learner/node_modules/on-change/source/smart-clone/clone/clone-date.js
generated
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import CloneObject from './clone-object.js';
|
||||
|
||||
export default class CloneDate extends CloneObject {
|
||||
undo(object) {
|
||||
object.setTime(this.clone.getTime());
|
||||
}
|
||||
|
||||
isChanged(value, equals) {
|
||||
return !equals(this.clone.valueOf(), value.valueOf());
|
||||
}
|
||||
}
|
||||
20
Frontend-Learner/node_modules/on-change/source/smart-clone/clone/clone-map.js
generated
vendored
Normal file
20
Frontend-Learner/node_modules/on-change/source/smart-clone/clone/clone-map.js
generated
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import {HANDLED_MAP_METHODS} from '../methods/map.js';
|
||||
import CloneObject from './clone-object.js';
|
||||
|
||||
export default class CloneMap extends CloneObject {
|
||||
static isHandledMethod(name) {
|
||||
return HANDLED_MAP_METHODS.has(name);
|
||||
}
|
||||
|
||||
undo(object) {
|
||||
for (const [key, value] of this.clone.entries()) {
|
||||
object.set(key, value);
|
||||
}
|
||||
|
||||
for (const key of object.keys()) {
|
||||
if (!this.clone.has(key)) {
|
||||
object.delete(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
115
Frontend-Learner/node_modules/on-change/source/smart-clone/clone/clone-object.js
generated
vendored
Normal file
115
Frontend-Learner/node_modules/on-change/source/smart-clone/clone/clone-object.js
generated
vendored
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
import path from '../../path.js';
|
||||
import isArray from '../../is-array.js';
|
||||
import isObject from '../../is-object.js';
|
||||
import {MUTABLE_ARRAY_METHODS} from '../methods/array.js';
|
||||
import {MUTABLE_SET_METHODS} from '../methods/set.js';
|
||||
import {MUTABLE_MAP_METHODS} from '../methods/map.js';
|
||||
import {IMMUTABLE_OBJECT_METHODS} from '../methods/object.js';
|
||||
|
||||
export default class CloneObject {
|
||||
constructor(value, path, argumentsList, hasOnValidate) {
|
||||
this._path = path;
|
||||
this._isChanged = false;
|
||||
this._clonedCache = new Set();
|
||||
this._hasOnValidate = hasOnValidate;
|
||||
this._changes = hasOnValidate ? [] : null;
|
||||
|
||||
this.clone = path === undefined ? value : this._shallowClone(value);
|
||||
}
|
||||
|
||||
static isHandledMethod(name) {
|
||||
return IMMUTABLE_OBJECT_METHODS.has(name);
|
||||
}
|
||||
|
||||
_shallowClone(value) {
|
||||
let clone = value;
|
||||
|
||||
if (isObject(value)) {
|
||||
clone = {...value};
|
||||
} else if (isArray(value) || ArrayBuffer.isView(value)) {
|
||||
clone = [...value];
|
||||
} else if (value instanceof Date) {
|
||||
clone = new Date(value);
|
||||
} else if (value instanceof Set) {
|
||||
clone = new Set([...value].map(item => this._shallowClone(item)));
|
||||
} else if (value instanceof Map) {
|
||||
clone = new Map();
|
||||
|
||||
for (const [key, item] of value.entries()) {
|
||||
clone.set(key, this._shallowClone(item));
|
||||
}
|
||||
}
|
||||
|
||||
this._clonedCache.add(clone);
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
preferredThisArg(isHandledMethod, name, thisArgument, thisProxyTarget) {
|
||||
if (isHandledMethod) {
|
||||
if (isArray(thisProxyTarget)) {
|
||||
this._onIsChanged = MUTABLE_ARRAY_METHODS[name];
|
||||
} else if (thisProxyTarget instanceof Set) {
|
||||
this._onIsChanged = MUTABLE_SET_METHODS[name];
|
||||
} else if (thisProxyTarget instanceof Map) {
|
||||
this._onIsChanged = MUTABLE_MAP_METHODS[name];
|
||||
}
|
||||
|
||||
return thisProxyTarget;
|
||||
}
|
||||
|
||||
return thisArgument;
|
||||
}
|
||||
|
||||
update(fullPath, property, value) {
|
||||
const changePath = path.after(fullPath, this._path);
|
||||
|
||||
if (property !== 'length') {
|
||||
let object = this.clone;
|
||||
|
||||
path.walk(changePath, key => {
|
||||
if (object?.[key]) {
|
||||
if (!this._clonedCache.has(object[key])) {
|
||||
object[key] = this._shallowClone(object[key]);
|
||||
}
|
||||
|
||||
object = object[key];
|
||||
}
|
||||
});
|
||||
|
||||
if (this._hasOnValidate) {
|
||||
this._changes.push({
|
||||
path: changePath,
|
||||
property,
|
||||
previous: value,
|
||||
});
|
||||
}
|
||||
|
||||
if (object?.[property]) {
|
||||
object[property] = value;
|
||||
}
|
||||
}
|
||||
|
||||
this._isChanged = true;
|
||||
}
|
||||
|
||||
undo(object) {
|
||||
let change;
|
||||
|
||||
for (let index = this._changes.length - 1; index !== -1; index--) {
|
||||
change = this._changes[index];
|
||||
|
||||
path.get(object, change.path)[change.property] = change.previous;
|
||||
}
|
||||
}
|
||||
|
||||
isChanged(value, _equals) {
|
||||
return this._onIsChanged === undefined
|
||||
? this._isChanged
|
||||
: this._onIsChanged(this.clone, value);
|
||||
}
|
||||
|
||||
isPathApplicable(changePath) {
|
||||
return path.isRootPath(this._path) || path.isSubPath(changePath, this._path);
|
||||
}
|
||||
}
|
||||
20
Frontend-Learner/node_modules/on-change/source/smart-clone/clone/clone-set.js
generated
vendored
Normal file
20
Frontend-Learner/node_modules/on-change/source/smart-clone/clone/clone-set.js
generated
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import {HANDLED_SET_METHODS} from '../methods/set.js';
|
||||
import CloneObject from './clone-object.js';
|
||||
|
||||
export default class CloneSet extends CloneObject {
|
||||
static isHandledMethod(name) {
|
||||
return HANDLED_SET_METHODS.has(name);
|
||||
}
|
||||
|
||||
undo(object) {
|
||||
for (const value of this.clone) {
|
||||
object.add(value);
|
||||
}
|
||||
|
||||
for (const value of object) {
|
||||
if (!this.clone.has(value)) {
|
||||
object.delete(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
27
Frontend-Learner/node_modules/on-change/source/smart-clone/clone/clone-weakmap.js
generated
vendored
Normal file
27
Frontend-Learner/node_modules/on-change/source/smart-clone/clone/clone-weakmap.js
generated
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import CloneObject from './clone-object.js';
|
||||
|
||||
export default class CloneWeakMap extends CloneObject {
|
||||
constructor(value, path, argumentsList, hasOnValidate) {
|
||||
super(undefined, path, argumentsList, hasOnValidate);
|
||||
|
||||
this._weakKey = argumentsList[0];
|
||||
this._weakHas = value.has(this._weakKey);
|
||||
this._weakValue = value.get(this._weakKey);
|
||||
}
|
||||
|
||||
isChanged(value, _equals) {
|
||||
return this._weakValue !== value.get(this._weakKey);
|
||||
}
|
||||
|
||||
undo(object) {
|
||||
const weakHas = object.has(this._weakKey);
|
||||
|
||||
if (this._weakHas && !weakHas) {
|
||||
object.set(this._weakKey, this._weakValue);
|
||||
} else if (!this._weakHas && weakHas) {
|
||||
object.delete(this._weakKey);
|
||||
} else if (this._weakValue !== object.get(this._weakKey)) {
|
||||
object.set(this._weakKey, this._weakValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
22
Frontend-Learner/node_modules/on-change/source/smart-clone/clone/clone-weakset.js
generated
vendored
Normal file
22
Frontend-Learner/node_modules/on-change/source/smart-clone/clone/clone-weakset.js
generated
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import CloneObject from './clone-object.js';
|
||||
|
||||
export default class CloneWeakSet extends CloneObject {
|
||||
constructor(value, path, argumentsList, hasOnValidate) {
|
||||
super(undefined, path, argumentsList, hasOnValidate);
|
||||
|
||||
this._argument1 = argumentsList[0];
|
||||
this._weakValue = value.has(this._argument1);
|
||||
}
|
||||
|
||||
isChanged(value, _equals) {
|
||||
return this._weakValue !== value.has(this._argument1);
|
||||
}
|
||||
|
||||
undo(object) {
|
||||
if (this._weakValue && !object.has(this._argument1)) {
|
||||
object.add(this._argument1);
|
||||
} else {
|
||||
object.delete(this._argument1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue