Code Monkey home page Code Monkey logo

slate-php's Introduction

slate-php's People

Contributors

e1himself avatar matej21 avatar spawnia avatar victorstanciu avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

matej21 mll-lab

slate-php's Issues

Support for Slate v0.50+

As Slate v0.50 is a complete overhaul, we need to rework this library to make it work with the new Slate model.

See Slate Changelog for v0.50.0:
https://github.com/ianstormtaylor/slate/blob/master/Changelog.md#0500--november-27-2019

A complete overhaul. The Slate codebase has had a complete overhaul and many pieces of its core architecture have been reconsidered from the ground up. There are lots of changes. We recommend re-reading the Walkthroughs and Concepts documentation and the Examples to get a sense for everything that has changed. As well as the Migration writeup for what the major changes are.

Help handle slate model version updates (v0.40 → v0.46)

Migrating content from one version to another is always a painful task. Especially when there are structural changes.

It would be great if this library did provide version-aware Value serialization.

A good example is Slate v0.46 update that merges Leaf and Text nodes data into Text node.

Before v0.46:

{
    "object": "text",
    "leaves": [
        {
            "object": "leaf",
            "text": "Hello",
            "marks": []
        }
    ]
}

After v0.46:

{
    "object": "text",
    "text": "Hello",
    "marks": []
}

Embrace immutability

A discussion started in #16

I think the library will benefit a lot from adoption the immutable model approach. So there is no way to modify an existing model instance, only create a new one with updated fields.

For example, PSR-7 HttpMessageInterface is following this practice: https://www.php-fig.org/psr/psr-7/

Tasks

  • Drop all setter methods from the model
  • Add withXxx methods to the model to create a new instance with modified properties
  • Provide unit tests

Example

Before:

$leaf = new Leaf('foo', [new Mark('type')]);

// Modify text
$leaf->setText(
    str_replace($leaf->getText(), 'o', 'a')
);
// Modify children
$leaf->setMarks(
    array_map(
        $leaf->getMarks(),
        function(Mark $mark): Mark {
            // modify mark
            // return modified mark
        }
    )
);

// $leaf is the instance, but mutated

After:

$leaf = new Leaf('foo', [new Mark('type')]);
// Modify text
$leaf = $leaf->withText(
    str_replace($leaf->getText(), 'o', 'a')
);
// Modify children
$leaf = $leaf->withMarks(
    array_map(
        $leaf->getMarks(),
        function(Mark $mark): Mark {
            // modify mark
            // return modified mark
        }
    )
);

// $leaf is a competely new instance of Leaf

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.