New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Self serializing nodes #16
Conversation
…bjects themselves
# Conflicts: # src/Model/Document.php # src/Model/Inline.php # src/Model/Leaf.php # src/Model/Mark.php # src/Model/Text.php # src/Model/Value.php # src/Unserializer.php
# Conflicts: # src/Model/Mark.php # src/Unserializer.php # tests/UnserializerTest.php
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @spawnia!
We're grateful for your effort to make this library better 👍
That's a great spirit!
However, this pull request is a huge dramatic change with multiple Backwards Incompatible changes.
I'd say it's better to name it a re-write of this library.
To summarize, here's a list of BC-breaking changes of this PR:
- All the getters are now replaced by public properties (BC break)
- Entity interface has been dropped (BC break)
- Node interface has been dropped (BC break)
- Unserializer has been dropped (BC break)
Also you've made a number of style changes that are not aligned with this repository's code-style.
- Our intention was to keep classes hierarchy domain-model-driven, not implementation-driven. That's why we think we should keep the
Node
andEntity
interfaces in the hierarchy, but there should not beJsonConvertible
orTextContainingNode
parent classes. - Our test methods are intentionally following the
it_should_
convention. We don't want it go.
That being said we cannot accept this pull request. Sorry.
What was the reason that you've decided to do such a dramatic rewrite? Do you have problems using the existing API in your project?
Thanks for your reply @e1himself I agree with your assessment concerning the scope of this PR, still i think the changes are worthwhile. The main reason for the changes is to align this implementation more closely with the reference implementation. The models there work similar to what i changed them to.
That makes programmatic manipulation of the nodes much easier. $leaf = new Leaf('foo', [new Mark('type')]);
// Modify text
// Before
$leaf->setText(
str_replace($leaf->getText(), 'o', 'a')
)
// After
str_replace($leaf->text, 'o', 'a')
// Modify children
// Before: Not possible atm, can only add. Given we added set:
$marks = $leaf->getMarks()
$leaf->setMarks(
array_map(
$marks,
function(Mark $mark): Mark {
// modify mark
// return modified mark
}
)
);
// After
foreach($leaf->marks as $mark){
// modify mark
} Static analysis can catch a misuse of those properties easily, and typed properties in PHP
I did not like how this interface was "all-knowing", holding all the constants of its children. In the other direction, all children depended on specific constants in there.
I replaced that with the
This also makes the API simpler and more powerful: // Unserializing a value
// Before
$unserializer = new Unserializer();
$unserializer->fromJSON('{}');
// After
Value::fromJSON('{}');
// Unserializing anything else
// Before: not possible
// After
Mark::fromJSON('{}');
Well the idiomatic PHPUnit way is to begin methods with If you really want it reverted, that is fine with me. I can change the PR if that is all that is holding it back. I hope i could clear up the intentions behind my changes. I am open to shaping this PR to a point where we can both agree on. It will not be possible without breaking changes though. |
|
Rearchitect the way nodes are serialized and align it more closely with Slate.
The functionality is the same as before, but the API is changed quite a bit.
The logic and rules for what each individual node may contain are now
contained within each node, instead of the monolithic
Unserializer
class.This allows deserialization at all levels of the object model.
Open to discussion if you think that changes are necessary :)