Comments (2)
Fixed with #24
from slate-php.
So now the library does support serialization and deserialization for multiple Slate JSON versions, making it possible to gradually migrate database content to the new Slate version. At the moment of writing this, prezly/slate-php
does support three (slightly) different JSON serialization formats (and can be extended to more in future):
- v0.27 ... v0.39 — block nodes with
isVoid
property - v0.40 ... v0.45 —
isVoid
dropped - v0.46 ... ? —
leaf
objects are not used anymore
This helps to disconnect Slate backend model upgrade from Slate frontend package.
Here's how we handle the v0.40 → v0.46 upgrade.
-
We've implemented a preconfigured Value serializer to be used throughout our application.
class DefaultSerializer implements ValueSerializer { /** @var string|null */ private $implied_version; /** @var string|null */ private $baseline_version; /** @var \Prezly\Slate\Serialization\ValueSerializer */ private $serializer; public function __construct(?string $implied_version = null, ?string $baseline_version = null) { $this->implied_version = $implied_version ?? '0.40'; $this->baseline_version = $baseline_version ?? '0.40'; $this->serializer = new Serializer($this->baseline_version, JSON_UNESCAPED_UNICODE); } public function toJson(Value $value, ?string $version = null): string { return $this->serializer->toJson($value, $version); } public function fromJson(string $value, ?string $default_version = null): Value { return $this->serializer->fromJson($value, $default_version ?? $this->implied_version); } }
-
The application always serializes/deserializes Slate values using the above DefaultSerializer. This allows us to normalize all the incoming slate content to the baseline version. Baseline version is the version of the frontend Slate JS package.
-
When the frontend is updated, we bump the baseline version to
0.46
to start generating the new Value JSON withoutleaf
objects. All the previously db-stored content will be automatically translated to the new0.46
format. -
We can then iterate over all the db values to gradually re-write them to the newest baseline version, if we want to.
from slate-php.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slate-php.