PolymerElements / iron-elements

Core elements
47 stars 23 forks source link

Element request: iron-serialize-remote & iron-serialize #52

Open anirudhb opened 6 years ago

anirudhb commented 6 years ago

Description

iron-serialize and iron-serialize-remote should be flexible, multi-use, serialization elements.

iron-serialize

iron-serialize should be a serialization/deserialization element. It should support all major data serialization formats, like XML, YAML, JSON, TOML, etc.

Example:

<!-- Note: 'yml' should also be considered YAML -->
<iron-serialize auto target="{{raw_obj}}" format="yaml" text="{{raw_yaml_text}}"></iron-serialize>
<!--
If raw_yaml_text is:
awesome: true
stuff:
  - one
  - two
  - three
Then raw_obj should be:
{
  awesome: true,
  stuff: ["one", "two", "three"]
}
-->

If the target object or the text changes, the other should be updated to reflect the changes. (Only if there is auto attribute. Use generateChanges to change manually.) Event for changing: change

iron-serialize-remote

iron-serialize-remote is just like iron-serialize, except it can serialize from a file (fetched with AJAX.) Catch: it cannot update the file if the target object changes. However, you should be able to register a callback which might save the text somewhere else.

This would also pass on the auto attribute to its internal iron-serialize.

In fact, this would be a very rough implementation:

<iron-ajax auto url="{{file}}" handle-as="text" last-response="{{_t1}}"></iron-ajax>
<iron-serialize auto target="{{obj}}" format="json" text="[[_t1]]"></iron-serialize>

Event for changing: change

Edit: Is iron-serialize-remote really needed?