Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #35260 > unrolled thread
| Started by | Andrew Poulos <ap_prog@hotmail.com> |
|---|---|
| First post | 2018-06-21 15:54 +1000 |
| Last post | 2018-06-21 17:01 -0700 |
| Articles | 20 on this page of 90 — 11 participants |
Back to article view | Back to comp.lang.javascript
Recording changes to an object Andrew Poulos <ap_prog@hotmail.com> - 2018-06-21 15:54 +1000
Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-21 01:47 -0700
Re: Recording changes to an object Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-06-21 17:01 +0100
Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-21 09:48 -0700
Re: Recording changes to an object John G Harris <niam@jghnorth.org.uk.invalid> - 2018-06-22 09:58 +0100
Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-06-21 21:03 +0200
Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-21 16:25 -0700
Re: Recording changes to an object Andrew Poulos <ap_prog@hotmail.com> - 2018-06-22 09:34 +1000
Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-21 17:02 -0700
Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-21 18:03 -0700
Re: Recording changes to an object John G Harris <niam@jghnorth.org.uk.invalid> - 2018-06-22 10:06 +0100
Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-22 02:21 -0700
Re: Recording changes to an object John G Harris <niam@jghnorth.org.uk.invalid> - 2018-06-22 18:31 +0100
Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-22 20:16 -0700
Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-06-22 02:23 +0200
Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-21 17:31 -0700
Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-06-22 02:55 +0200
Re: Recording changes to an object Andrew Poulos <ap_prog@hotmail.com> - 2018-06-22 12:37 +1000
Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-22 02:23 -0700
Re: Recording changes to an object Jake Jarvis <pig_in_shoes@yahoo.com> - 2018-06-22 14:35 +0200
Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-22 05:57 -0700
Re: Recording changes to an object Mickey Finn <mfinn@gmail.com> - 2018-06-22 15:43 -0300
Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-06-22 13:51 +0200
Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-22 06:04 -0700
Re: Recording changes to an object John G Harris <niam@jghnorth.org.uk.invalid> - 2018-06-22 18:33 +0100
Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-06-24 14:36 +0200
Re: Recording changes to an object "Mark-" <nospam@mapson.xyz> - 2018-06-24 13:56 +0000
Re: Recording changes to an object John G Harris <niam@jghnorth.org.uk.invalid> - 2018-06-25 10:06 +0100
Re: Recording changes to an object Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-06-25 02:40 -0700
Re: Recording changes to an object Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-06-25 02:47 -0700
Re: Recording changes to an object Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-06-25 02:51 -0700
Re: Recording changes to an object Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-06-25 02:54 -0700
Re: Recording changes to an object Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-06-25 02:58 -0700
Re: Recording changes to an object John G Harris <niam@jghnorth.org.uk.invalid> - 2018-06-25 19:26 +0100
Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-06-30 19:47 +0200
Re: Recording changes to an object John G Harris <niam@jghnorth.org.uk.invalid> - 2018-07-01 10:56 +0100
Re: Recording changes to an object Andrew Poulos <ap_prog@hotmail.com> - 2018-06-23 17:19 +1000
Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-23 00:51 -0700
Re: Recording changes to an object John G Harris <niam@jghnorth.org.uk.invalid> - 2018-06-23 11:27 +0100
Re: Recording changes to an object Andrew Poulos <ap_prog@hotmail.com> - 2018-06-23 20:59 +1000
Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-23 05:51 -0700
Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-06-30 19:43 +0200
Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-01 15:22 +0200
Re: Recording changes to an object Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2018-07-02 16:29 +0200
Cloning an object (was: Recording changes to an object) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-04 23:25 +0200
Re: Cloning an object Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2018-07-05 10:00 +0200
Re: Cloning an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-05 19:49 +0200
Re: Cloning an object Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2018-07-05 20:37 +0200
Re: Cloning an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-05 23:35 +0200
Re: Cloning an object Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2018-07-05 23:54 +0200
Re: Cloning an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-06 00:32 +0200
Re: Cloning an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-06 00:24 +0200
Re: Cloning an object John G Harris <niam@jghnorth.org.uk.invalid> - 2018-07-06 18:48 +0100
Re: Cloning an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-06 23:51 +0200
Re: Cloning an object John G Harris <niam@jghnorth.org.uk.invalid> - 2018-07-07 15:51 +0100
Re: Cloning an object Julio Di Egidio <julio@diegidio.name> - 2018-07-07 08:39 -0700
Re: Cloning an object John G Harris <niam@jghnorth.org.uk.invalid> - 2018-07-09 10:20 +0100
Re: Cloning an object Julio Di Egidio <julio@diegidio.name> - 2018-07-09 02:35 -0700
Re: Cloning an object Julio Di Egidio <julio@diegidio.name> - 2018-07-09 02:41 -0700
Re: Cloning an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-08 12:20 +0200
Re: Cloning an object John G Harris <niam@jghnorth.org.uk.invalid> - 2018-07-08 14:38 +0100
Re: Cloning an object Julio Di Egidio <julio@diegidio.name> - 2018-07-08 13:10 -0700
Re: Cloning an object John G Harris <niam@jghnorth.org.uk.invalid> - 2018-07-09 09:48 +0100
Re: Cloning an object Julio Di Egidio <julio@diegidio.name> - 2018-07-09 02:28 -0700
Re: Cloning an object Julio Di Egidio <julio@diegidio.name> - 2018-07-09 02:38 -0700
Re: Cloning an object John G Harris <niam@jghnorth.org.uk.invalid> - 2018-07-09 19:11 +0100
Re: Recording changes to an object "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-07-02 21:01 -0700
Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-05 00:32 +0200
Re: Recording changes to an object "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-07-04 19:23 -0700
Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-05 06:38 +0200
Re: Recording changes to an object "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-07-04 23:21 -0700
Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-05 09:25 +0200
Re: Recording changes to an object "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-07-05 07:44 -0700
Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-05 19:35 +0200
Re: Recording changes to an object "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-07-06 12:59 -0700
Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-06 23:22 +0200
Re: Recording changes to an object "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-07-07 12:45 -0700
Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-08 11:13 +0200
Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-07-08 05:03 -0700
Re: Recording changes to an object "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-07-08 13:42 -0700
Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-07-08 13:46 -0700
Re: Recording changes to an object "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-07-08 13:41 -0700
Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-09 00:35 +0200
Re: Recording changes to an object "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-07-10 01:03 -0700
Re: Recording changes to an object Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-10 20:50 +0200
Re: Recording changes to an object "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-07-10 16:09 -0700
Re: Recording changes to an object "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-06-21 15:09 -0700
Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-21 16:30 -0700
Re: Recording changes to an object "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-06-21 16:57 -0700
Re: Recording changes to an object Julio Di Egidio <julio@diegidio.name> - 2018-06-21 17:01 -0700
Page 1 of 5 [1] 2 3 4 5 Next page →
| From | Andrew Poulos <ap_prog@hotmail.com> |
|---|---|
| Date | 2018-06-21 15:54 +1000 |
| Subject | Recording changes to an object |
| Message-ID | <aYCdnU3Tes0_oLbGnZ2dnUU7-LHNnZ2d@westnet.com.au> |
If I have a some what large object (ie an object with lots of properties
that looks like:
var obj = {
"1": {"a":1,
"b":"data:text/plain;charset=UTF-8;page=21,the%20data:1234,5678", "c":3,
...},
"2": {"a":2, ...
"3": ...
...
};
You cannot add or delete any property from a top level value eg within
the object {"a":1, "b"... )
All the top level values have the same properties.
Top level properties may be added or deleted.
Is their some approach I can follow to make a multiple level undo?
I started by making copies of the object each time it was changed but
within minutes there was a huge number of copies. I thought about
limiting the undo level to, say, 8 levels but if you set a property
value to the value it currently is (ie. you don't actually change the
value) it was still recording it as a change - so trying to do an undo
did "nothing".
I need something that does:
1. Has the object has been changed?
2. If, yes, what was the change eg obj['1'].a value changed from 1 to 2
3. When the user calls undo it finds the change and reverses it.
Andrew Poulos
[toc] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2018-06-21 01:47 -0700 |
| Message-ID | <5019d5c0-f469-46b7-a50f-73d79186e714@googlegroups.com> |
| In reply to | #35260 |
On Thursday, 21 June 2018 07:54:51 UTC+2, Andrew Poulos wrote: > Is their some approach I can follow to make a multiple level undo? > > I started by making copies of the object each time it was changed but > within minutes there was a huge number of copies. Do not copy the whole object, just record the changes. > if you set a property > value to the value it currently is You'd have to wrap your data object within some container object, so that every property write is checked and a change, only if there is any, is applied to the underlying data as well as it gets recorded (which property or sub-property was changed, the old value, the new value). The wrapper would also expose the undo/redo functionality. HTH, Julio
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2018-06-21 17:01 +0100 |
| Message-ID | <87po0kruvd.fsf@bsb.me.uk> |
| In reply to | #35260 |
Andrew Poulos <ap_prog@hotmail.com> writes: <snip> > Is their some approach I can follow to make a multiple level undo? <snip> > I need something that does: > > 1. Has the object has been changed? > 2. If, yes, what was the change eg obj['1'].a value changed from 1 to 2 > 3. When the user calls undo it finds the change and reverses it. I would consider storing the changes as a list of functions. When you make a change, you also make a change-reversing function. Depending on the structure of the code that makes the changes, the reversing function could be quite simple. -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2018-06-21 09:48 -0700 |
| Message-ID | <da593d89-1aa2-4e43-8323-4ea9e92d5a50@googlegroups.com> |
| In reply to | #35262 |
On Thursday, 21 June 2018 18:02:05 UTC+2, Ben Bacarisse wrote: > Andrew Poulos <ap_prog@hotmail.com> writes: > <snip> > > Is their some approach I can follow to make a multiple level undo? > <snip> > > I need something that does: > > > > 1. Has the object has been changed? > > 2. If, yes, what was the change eg obj['1'].a value changed from 1 to 2 > > 3. When the user calls undo it finds the change and reverses it. > > I would consider storing the changes as a list of functions. When you > make a change, you also make a change-reversing function. Depending on > the structure of the code that makes the changes, the reversing function > could be quite simple. I'd strongly advise against: perfect example of "clever" spaghetti... Julio
[toc] | [prev] | [next] | [standalone]
| From | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2018-06-22 09:58 +0100 |
| Message-ID | <2iepidl1ua4isnu6ovdr0d9rbmk6tg87i4@4ax.com> |
| In reply to | #35263 |
On Thu, 21 Jun 2018 09:48:44 -0700 (PDT), Julio Di Egidio <julio@diegidio.name> wrote: <snip> >I'd strongly advise against: perfect example of "clever" spaghetti... Is it that you think that no more than one level of Undo is required ? Or is it that you have a neat way to remember thousands of Undo descriptions ? John
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2018-06-21 21:03 +0200 |
| Message-ID | <1620852.VI2in3QvqR@PointedEars.de> |
| In reply to | #35260 |
Andrew Poulos wrote:
> If I have a some what large object (ie an object with lots of properties
> that looks like:
>
> var obj = {
> "1": {"a":1,
> "b":"data:text/plain;charset=UTF-8;page=21,the%20data:1234,5678", "c":3,
> ...},
> "2": {"a":2, ...
> "3": ...
> ...
> };
>
> You cannot add or delete any property from a top level value eg within
> the object {"a":1, "b"... )
> All the top level values have the same properties.
> Top level properties may be added or deleted.
>
> Is their some approach I can follow to make a multiple level undo?
Yes.
> I started by making copies of the object each time it was changed but
> within minutes there was a huge number of copies. I thought about
> limiting the undo level to, say, 8 levels but if you set a property
> value to the value it currently is (ie. you don't actually change the
> value) it was still recording it as a change - so trying to do an undo
> did "nothing".
Yes, that is a terrible idea in the first place.
> I need something that does:
>
> 1. Has the object has been changed?
> 2. If, yes, what was the change eg obj['1'].a value changed from 1 to 2
> 3. When the user calls undo it finds the change and reverses it.
Property changes should only be possible via setter. You can either make
the actual properties private and have a getter that returns their actual
value –
var o = Object.create(null, (function () {
var _foo;
return {
foo: {
"get": function () {
return _foo;
},
"set": function (value) {
// …
_foo = value;
// …
}
}
};
}()));
–, or you can use a Proxy:
var o = new Proxy(Object.create(null), {
"get": function (target, name) {
return target[name];
},
"set": function (target, name, value) {
// …
target[name] = value;
// …
},
deleteProperty: function (target, prop) {
// …
var success = delete target[prop];
// …
return success;
}
});
[I am deliberately quoting “get” and “set” here because they had been
reserved words in at least one implementation once.]
Then in the setter/trap you can update the item of a Map, where you use the
object reference as the key, with the pertinent information:
var all_changes = new Map();
var o = {};
var changes = all_changes.get(o);
var change = Object.assign(Object.create(null), {…});
changes ? changes.push(change) : all_changes.set(o, [change]);
If you cannot use native Map, you can use my jsx.map.Map or something
similar. If you cannot use that too, you can find some way to determine
a path of an object to be modified as a string and use that as the key
for an object instance (that is what jsx.map.Map does if the key is a
reference to an object).
As an alternative you can use special, otherwise unused, properties in the
same object to record the changes. If so, it will be good if the prototype
chain of the target object is empty. You could also use my
jsx.object.findNewProperty() to determine an unused property name.
An Array of objects will be useful for the undo list.
Proof of concept:
var UNDO_ADD = 1;
var UNDO_MODIFY = 2;
var UNDO_DELETE = 3;
function setProperty (obj, name, newValue)
{
var undo_record = Object.create(null);
var old_value = obj[name];
if (!(name in obj))
{
Object.assign(undo_record, {
action: UNDO_ADD,
name: name,
value: newValue
});
}
else if ((old_value = obj[name]) !== newValue)
{
Object.assign(undo_record, {
action: UNDO_MODIFY,
name: name,
oldValue: old_value,
newValue: newValue
});
}
obj[name] = newValue;
(obj._changes || (obj._changes = [])).push(undo_record);
}
function deleteProperty (obj, name)
{
if (name in obj)
{
var value = obj[name];
if (delete obj[name])
{
var undo_record = Object.assign(Object.create(null), {
action: UNDO_DELETE,
name: name,
value: value
});
(obj._changes || (obj._changes = [])).push(undo_record);
}
}
}
var obj = Object.create(null);
setProperty(obj, "foo", "bar");
setProperty(obj, "foo", "baz");
deleteProperty(obj, "foo");
obj._changes
Implementation of the rollback is left as an exercise to the reader.
Do not use Object.prototype.watch() as it is proprietary and deprecated:
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/watch>
--
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2018-06-21 16:25 -0700 |
| Message-ID | <2166d0b2-c51c-4a87-9b30-7008349640fe@googlegroups.com> |
| In reply to | #35264 |
On Thursday, 21 June 2018 21:04:05 UTC+2, Thomas 'PointedEars' Lahn wrote:
> Andrew Poulos wrote:
>
> > If I have a some what large object (ie an object with lots of properties
> > that looks like:
> >
> > var obj = {
> > "1": {"a":1,
> > "b":"data:text/plain;charset=UTF-8;page=21,the%20data:1234,5678", "c":3,
> > ...},
> > "2": {"a":2, ...
> > "3": ...
> > ...
> > };
> >
> > You cannot add or delete any property from a top level value eg within
> > the object {"a":1, "b"... )
> > All the top level values have the same properties.
> > Top level properties may be added or deleted.
> >
> > Is their some approach I can follow to make a multiple level undo?
>
> Yes.
>
> > I started by making copies of the object each time it was changed but
> > within minutes there was a huge number of copies. I thought about
> > limiting the undo level to, say, 8 levels but if you set a property
> > value to the value it currently is (ie. you don't actually change the
> > value) it was still recording it as a change - so trying to do an undo
> > did "nothing".
>
> Yes, that is a terrible idea in the first place.
How is your answer different from mine? IOW, couldn't you restart from there
instead of restarting from zero (which includes objecting to anything if you
like and so on).
Mind you, I sincerely mean please engage or go fuck yourself: and with all due
respect as I think you can do much better than just playing the autistic moron.
And this is an offer of respect and collaboration which I will not extend again.
Julio
[toc] | [prev] | [next] | [standalone]
| From | Andrew Poulos <ap_prog@hotmail.com> |
|---|---|
| Date | 2018-06-22 09:34 +1000 |
| Message-ID | <Wcidne3I2Pl2qLHGnZ2dnUU7-XPNnZ2d@westnet.com.au> |
| In reply to | #35264 |
On 22/06/2018 5:03 AM, Thomas 'PointedEars' Lahn wrote: > Property changes should only be possible via setter. You can either make > the actual properties private and have a getter that returns their actual > value – [nice code clipped] Great thanks, it looks an implementation of the same idea as Julio's. And it looks like it's something I can implement without too much pain. I just need to go through the dozens of places that the object is currently changed and implement the getter/setter. Typically when dealing with a "large" object is it "better" to use a getter/setter than just accessing the object directly? Andrew Poulos
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2018-06-21 17:02 -0700 |
| Message-ID | <e9ffe96f-9314-4b40-881d-cd48b8655269@googlegroups.com> |
| In reply to | #35269 |
On Friday, 22 June 2018 01:34:13 UTC+2, Andrew Poulos wrote: > Typically when dealing with a "large" object is it "better" to use a > getter/setter than just accessing the object directly? Generally you should code for/think in terms of *access patterns*, whatever the object: but how to write the code remains very specific... (Just for comparison, take Ben Bacarisse's solution: he essentially suggest OO by the letter, i.e. an object encapsulates data as well as the methods that act on the data. Now take note: except in *very* exceptional cases, the exact opposite is the way to go: who does what and the data/state is just data/ state... HTH.) Julio
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2018-06-21 18:03 -0700 |
| Message-ID | <375fd341-9a26-4603-92b3-bf3c47d83c7a@googlegroups.com> |
| In reply to | #35272 |
On Friday, 22 June 2018 02:02:30 UTC+2, Julio Di Egidio wrote: > Generally you should code for/think in terms of *access patterns*, whatever the > object: but how to write the code remains very specific... P.S. But a golden rule remains keep it as simple as you can: e.g. don't use a factory where you just want a single object, think what functions you need to implement, otherwise don't go into meta-programming unless it's a requirement! Indeed, I don't like Thomas' last answer, it's already way beyond the point... Julio
[toc] | [prev] | [next] | [standalone]
| From | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2018-06-22 10:06 +0100 |
| Message-ID | <c0fpidt5517ebl943m1csuchkk813l2s6v@4ax.com> |
| In reply to | #35272 |
On Thu, 21 Jun 2018 17:02:25 -0700 (PDT), Julio Di Egidio <julio@diegidio.name> wrote: <snip> >(Just for comparison, take Ben Bacarisse's solution: he essentially suggest OO >by the letter, i.e. an object encapsulates data as well as the methods that act >on the data. Now take note: except in *very* exceptional cases, the exact >opposite is the way to go: who does what and the data/state is just data/ >state... HTH.) You're saying it's wrong for each Undo description to remember which Undo function is to be applied because that information belongs elsewhere. Also you're saying that Redo functions must be separate from Do functions. I don't agree. John
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2018-06-22 02:21 -0700 |
| Message-ID | <4c987c41-ac44-4393-9810-ba78b4cf4df7@googlegroups.com> |
| In reply to | #35279 |
On Friday, 22 June 2018 11:06:41 UTC+2, John G Harris wrote: > On Thu, 21 Jun 2018 17:02:25 -0700 (PDT), Julio Di Egidio > <julio@diegidio.name> wrote: > > <snip> > >(Just for comparison, take Ben Bacarisse's solution: he essentially suggest OO > >by the letter, i.e. an object encapsulates data as well as the methods that act > >on the data. Now take note: except in *very* exceptional cases, the exact > >opposite is the way to go: who does what and the data/state is just data/ > >state... HTH.) > > You're saying it's wrong for each Undo description to remember which > Undo function is to be applied because that information belongs > elsewhere. Also you're saying that Redo functions must be separate > from Do functions. You guys are a bunch of retarded shitheads, you fucking idiot and liar #927. No worries, I'll keep pointing the bullshit and the insanity, out of pure fun if nothing else... *Plonk* Julio
[toc] | [prev] | [next] | [standalone]
| From | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2018-06-22 18:31 +0100 |
| Message-ID | <3ecqidtgsonpk5h8u19pj98tfh9mr207t8@4ax.com> |
| In reply to | #35280 |
On Fri, 22 Jun 2018 02:21:53 -0700 (PDT), Julio Di Egidio <julio@diegidio.name> wrote: >On Friday, 22 June 2018 11:06:41 UTC+2, John G Harris wrote: >> On Thu, 21 Jun 2018 17:02:25 -0700 (PDT), Julio Di Egidio >> <julio@diegidio.name> wrote: >> >> <snip> >> >(Just for comparison, take Ben Bacarisse's solution: he essentially suggest OO >> >by the letter, i.e. an object encapsulates data as well as the methods that act >> >on the data. Now take note: except in *very* exceptional cases, the exact >> >opposite is the way to go: who does what and the data/state is just data/ >> >state... HTH.) >> >> You're saying it's wrong for each Undo description to remember which >> Undo function is to be applied because that information belongs >> elsewhere. Also you're saying that Redo functions must be separate >> from Do functions. > >You guys are a bunch of retarded shitheads, you fucking idiot and liar #927. > >No worries, I'll keep pointing the bullshit and the insanity, out of pure fun >if nothing else... Ah, a technical answer. Are you sure you're qualified to be so technical? John
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2018-06-22 20:16 -0700 |
| Message-ID | <48a4bb29-50ad-4574-bbd7-add21519a72a@googlegroups.com> |
| In reply to | #35286 |
On Friday, 22 June 2018 19:31:50 UTC+2, John G Harris wrote: > Ah, a technical answer. Are you sure you're qualified to be so > technical? And still the same bullshit from your side. FUCK YOU: morons, pieces of stupid shit, and polluters of this planet. Julio
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2018-06-22 02:23 +0200 |
| Message-ID | <7975861.kMSeZ0AfC3@PointedEars.de> |
| In reply to | #35269 |
Andrew Poulos wrote:
> Great thanks, it looks an implementation of the same idea as Julio's.
Possibly; I have the troll killfiled.
> And it looks like it's something I can implement without too much pain.
> I just need to go through the dozens of places that the object is
> currently changed and implement the getter/setter.
You only have to do that if you cannot use Proxy. Otherwise:
/* original code that defines o */
o = new Proxy(o, {
/* traps */
});
/* original code that uses o */
> Typically when dealing with a "large" object is it "better" to use a
> getter/setter than just accessing the object directly?
Mu.
--
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2018-06-21 17:31 -0700 |
| Message-ID | <42a382fe-6a0a-45c0-8eb8-387e636ebba4@googlegroups.com> |
| In reply to | #35273 |
On Friday, 22 June 2018 02:23:35 UTC+2, Thomas 'PointedEars' Lahn wrote: > Andrew Poulos wrote: > > > Great thanks, it looks an implementation of the same idea as Julio's. > > Possibly; I have the troll killfiled. Idiot, I surmise you don't even know what troll means. Moron. Will you guys ever get your head out of your ass? A rhetorical question... *Plonk* Julio
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2018-06-22 02:55 +0200 |
| Message-ID | <1643274.5VXe1CXSyS@PointedEars.de> |
| In reply to | #35269 |
Andrew Poulos wrote:
> On 22/06/2018 5:03 AM, Thomas 'PointedEars' Lahn wrote:
>> Property changes should only be possible via setter. You can either make
>> the actual properties private and have a getter that returns their
>> actual value –
>
> [nice code clipped]
>
> Great thanks, it looks an implementation of the same idea as Julio's.
> And it looks like it's something I can implement without too much pain.
> I just need to go through the dozens of places that the object is
> currently changed and implement the getter/setter.
Depending on what you mean by that, you might not be aware that even if you
cannot use Proxy you may not have to implement the getter/setter in multiple
places:
/* code that defines o */
function proxify (target, propertyNames)
{
propertyNames.forEach(function (name) {
var _p = this[name];
/*
Object.defineProperty(this, name, {
"get": function () {
return _p;
},
"set": function (value) {
// …
_p = value;
// …
}
});
}, target);
}
proxify(o, [propertyName1, propertyName2]);
/* code that uses o */
Note that by having a top-level setter you can make sure that sub-level
properties also use a setter: just convert the assigned value, if it is a
reference to an object, to a reference to a object whose relevant properties
have setters.
You can do the same with Proxy, but there also for yet unknown properties;
also, only with Proxy you can trap deletion of properties.
Note also that getters and setters have been supported in some
implementation before Object.defineProperty(), with
Object.prototype.__defineGetter__() and Object.prototype.__defineSetter__(),
which you can use as a fallback in Object.defineProperty() polyfill (as I do
in JSX:object.js).
--
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | Andrew Poulos <ap_prog@hotmail.com> |
|---|---|
| Date | 2018-06-22 12:37 +1000 |
| Message-ID | <bJCdneFksfFi_bHGnZ2dnUU7-SvNnZ2d@westnet.com.au> |
| In reply to | #35275 |
On 22/06/2018 10:55 AM, Thomas 'PointedEars' Lahn wrote:
> Andrew Poulos wrote:
>
>> On 22/06/2018 5:03 AM, Thomas 'PointedEars' Lahn wrote:
>>> Property changes should only be possible via setter. You can either make
>>> the actual properties private and have a getter that returns their
>>> actual value –
>>
>> [nice code clipped]
>>
>> Great thanks, it looks an implementation of the same idea as Julio's.
>> And it looks like it's something I can implement without too much pain.
>> I just need to go through the dozens of places that the object is
>> currently changed and implement the getter/setter.
>
> Depending on what you mean by that, you might not be aware that even if you
> cannot use Proxy you may not have to implement the getter/setter in multiple
> places:
>
> /* code that defines o */
>
> function proxify (target, propertyNames)
> {
> propertyNames.forEach(function (name) {
> var _p = this[name];
>
> /*
> Object.defineProperty(this, name, {
> "get": function () {
> return _p;
> },
> "set": function (value) {
> // …
> _p = value;
> // …
> }
> });
> }, target);
> }
>
> proxify(o, [propertyName1, propertyName2]);
>
> /* code that uses o */
>
> Note that by having a top-level setter you can make sure that sub-level
> properties also use a setter: just convert the assigned value, if it is a
> reference to an object, to a reference to a object whose relevant properties
> have setters.
>
> You can do the same with Proxy, but there also for yet unknown properties;
> also, only with Proxy you can trap deletion of properties.
>
> Note also that getters and setters have been supported in some
> implementation before Object.defineProperty(), with
> Object.prototype.__defineGetter__() and Object.prototype.__defineSetter__(),
> which you can use as a fallback in Object.defineProperty() polyfill (as I do
> in JSX:object.js).
Thanks for the comprehensive replies. My next task is not to code but to
learn more about proxies.
Andrew Poulos
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2018-06-22 02:23 -0700 |
| Message-ID | <7f2fc3de-356a-4c8f-b06f-b68957eece15@googlegroups.com> |
| In reply to | #35277 |
On Friday, 22 June 2018 04:38:00 UTC+2, Andrew Poulos wrote: > Thanks for the comprehensive replies. Thank you for not thanking me ever: now the gifts are over. Moron. *Plonk* Julio
[toc] | [prev] | [next] | [standalone]
| From | Jake Jarvis <pig_in_shoes@yahoo.com> |
|---|---|
| Date | 2018-06-22 14:35 +0200 |
| Message-ID | <pgiqee$2ns$1@dont-email.me> |
| In reply to | #35281 |
Am 22.06.2018 um 11:23 schrieb Julio Di Egidio: > On Friday, 22 June 2018 04:38:00 UTC+2, Andrew Poulos wrote: > >> Thanks for the comprehensive replies. > > Thank you for not thanking me ever: now the gifts are over. Moron. > > *Plonk* > > Julio > What is that *Plonk* thing? Is that like "yoink" when stealing things? Just something you do?
[toc] | [prev] | [next] | [standalone]
Page 1 of 5 [1] 2 3 4 5 Next page →
Back to top | Article view | comp.lang.javascript
csiph-web