Skip to content

Commit b66767b

Browse files
committed
props
1 parent da256f4 commit b66767b

File tree

3 files changed

+89
-43
lines changed

3 files changed

+89
-43
lines changed

simply.js

+79-32
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ simply = {
829829
this.dom = dom;
830830
this.lifecycle = lifecycle;
831831

832-
this.propsToObserve = props;
832+
this.props = props;
833833

834834
this.dataToObserve = data;
835835
this.data;
@@ -968,7 +968,7 @@ simply = {
968968
mutations.forEach(function (mutation) {
969969
if (mutation.type === 'attributes') {
970970
var newVal = mutation.target.getAttribute(mutation.attributeName);
971-
//console.log(mutation.attributeName, "attribute changed to", newVal);
971+
console.log(mutation.attributeName, "attribute changed to", newVal);
972972
callback(mutation.attributeName, newVal);
973973

974974
}
@@ -990,23 +990,27 @@ simply = {
990990
}
991991
connectedCallback() {
992992
this.observeAttrChange(this, function (name, newValue) {
993+
console.log("hee");
993994
// value öncekiyle aynı değilse
994995
// console.log(name, newValue, self.props[name], newValue == simply.prepareAttr(self.props[name]));
995-
if (newValue !== simply.prepareAttr(self.props[name])) {
996-
try {
997-
newValue = simply.parseProp(newValue).value;
998-
} catch (e) {
999-
// getattribute parse edemezse
1000-
newValue = newValue;
1001-
}
1002-
1003-
self.props[name] = newValue;
1004-
if (typeof self.lifecycle !== "undefined") {
1005-
if (typeof self.lifecycle.whenPropChange !== "undefined") {
1006-
console.log("propchange");
1007-
self.lifecycle.whenPropChange(name, self.props[name], newValue);
996+
if (self.props[name]) {
997+
if (newValue !== simply.prepareAttr(self.props[name])) {
998+
try {
999+
newValue = simply.parseProp(newValue).value;
1000+
} catch (e) {
1001+
// getattribute parse edemezse
1002+
newValue = newValue;
1003+
}
1004+
1005+
self.props[name] = newValue;
1006+
if (typeof self.lifecycle !== "undefined") {
1007+
if (typeof self.lifecycle.whenPropChange !== "undefined") {
1008+
console.log("propchange");
1009+
self.lifecycle.whenPropChange(name, self.props[name], newValue);
1010+
}
10081011
}
1009-
}
1012+
}
1013+
10101014
}
10111015
});
10121016

@@ -1075,33 +1079,77 @@ simply = {
10751079
}
10761080
}
10771081

1078-
if (this.propsToObserve) {
1079-
this.props = ObservableSlim.create(this.propsToObserve, true, function (changes) {
1080-
for (const [key, cb] of Object.entries(self.cb.props)) {
1081-
if (cb) {
1082-
changes.forEach(function (change, key) {
1083-
if (change.newValue !== change.previousValue) {
1084-
changes.forEach(function (change, key) {
1085-
cb(change.property, change.newValue, change.previousValue, true);
1086-
});
1082+
if (this.props) {
1083+
let handler = {
1084+
get: function (obj, prop) {
1085+
1086+
// props can contain only key: value not key: object
1087+
// so no need to proxify child nodes
1088+
1089+
/*
1090+
if (isObjectWithoutTriggeringGetter(obj, prop) ) {
1091+
console.log(proxies, obj[prop], r);
1092+
if (proxies.has(obj[prop])) {
1093+
// console.log("uyy proxy daaa", obj[prop]);
1094+
return proxies.get(obj[prop]);
1095+
}
1096+
else {
1097+
// console.log("obje proxy'e dönüştürüldü", obj, prop);
1098+
let proxy = new Proxy(obj[prop], handler);
1099+
//proxies.add(proxy);
1100+
proxies.set(obj[prop], proxy);
1101+
return proxy;
1102+
}
1103+
1104+
}
1105+
else {
1106+
//console.log("normal get", obj, prop);
1107+
return obj[prop];
1108+
}
1109+
*/
1110+
return obj[prop];
1111+
},
1112+
set: function (target, prop, value, receiver) {
1113+
if (target[prop] !== value) {
1114+
Reflect.set(...arguments);
1115+
for (const [key, cb] of Object.entries(self.cb.props)) {
1116+
if (cb) {
1117+
1118+
cb(prop, value);
10871119
}
1088-
})
1120+
1121+
//console.log(`${key}: ${value}`);
1122+
}
1123+
}
1124+
return true; // Pass through the operation
1125+
},
1126+
deleteProperty: function (target, prop) {
1127+
if (prop in target) {
1128+
delete target[prop];
1129+
//console.log(`property removed: ${prop}`);
1130+
// Expected output: "property removed: texture"
1131+
}
1132+
for (const [key, cb] of Object.entries(self.cb.props)) {
1133+
cb(prop, null);
1134+
//console.log(`${key}: ${value}`);
10891135
}
10901136
}
1091-
});
1137+
};
10921138

10931139
if (template.indexOf("props.") > -1 || script.indexOf("props.") > -1) {
10941140
this.cb.props = {}
1095-
this.cb.props[this.uid] = function (property, newValue, previousValue) { self.react(property, newValue, previousValue, true) };
1141+
this.cb.props[this.uid] = function (prop, value) { self.react(prop, value, true) };
1142+
this.props = new Proxy(this.props, handler);
10961143
this.setProps(this.props);
10971144
this.setCbProps(this.cb.props);
10981145
}
1146+
10991147
}
11001148

11011149
if (this.stateToObserve) {
11021150
if (!this.stateToObserve.__isProxy) {
11031151
this.state = ObservableSlim.create(this.stateToObserve, true, function (changes) {
1104-
console.log(changes, templateName);
1152+
// console.log(changes, templateName);
11051153
if (self.cb.state) {
11061154
for (const [key, cb] of Object.entries(self.cb.state)) {
11071155
if (cb) {
@@ -1116,16 +1164,15 @@ simply = {
11161164
this.cb.state = {}
11171165
this.cb.state[this.uid] = function (property, newValue, previousValue) { self.react(property, newValue, previousValue) };
11181166
this.setCbState(this.cb.state);
1119-
console.log("bu bi kere çalışır");
1167+
//console.log("bu bi kere çalışır");
11201168
// this.state = new Proxy(this.state, handler);
11211169

11221170
}
11231171
else {
1124-
console.log(this.parent.state);
11251172
this.state = this.parent.state
11261173
if (template.indexOf("state.") > -1 || script.indexOf("state.") > -1) {
11271174
var p = findElementWithCB(this.parent);
1128-
console.log("ppp", p, this.parent, templateName);
1175+
// console.log("ppp", p, this.parent, templateName);
11291176
p.cb.state[this.uid] = function (property, newValue, previousValue) { self.react(property, newValue, previousValue) };
11301177
// this.state = new Proxy(this.state, handler);
11311178
}

simply.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

simply.min.js.map

+9-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)