Git Product home page Git Product logo

blazon's People

Contributors

mtwilliams avatar tsutsu avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

tsutsu meetwalter

blazon's Issues

Automatic fragment caching?

This could/should be handled about another package, say blazon_auto_cache.

It would cache based on the input objects and options. It would likely need a key to disambiguate objects, which could be deduced from Ecto schema or manually specified via an option.

Always use a generator function for serialization.

This would wrap immediate values in something like &(Map.get(&1, <field>)). More sophisticated fetching would have the same interface. This could be extended to allow wrapping in another fun (monadic!) to implement #21 for example.

Extend our intermediate format to include meta.

Given something like,

defmodule Person do
  defstruct ~w(name)a
end

defmodule PersonSerializer do
  use Blazon.Serializable
  field name, :string
  field gender, enum: [type: :gender, ~w(male female)a], via: fn (person) ->
    if String.contains?("John")
      :male
    else
      :female
    end
  end
end

We should produce an intermediate form like so:

iex(1)> Blazon.intermediate([PersonSerializer], [%Person{name: "John Doe"}, %Person{name: "Jane Doe"}])
{[[{:name, [type: :string], "John Doe"},
   {:gender, [type: {:enum, [name: :gender], [:male, :female]}], :male}],
  [{:name, [type: :string], "Jane Doe"},
   {:gender, [type: {:enum, [name: :gender], [:male, :female]}], :female}],
 [type: [People]]}

This will allow more structured serializers i.e. xml to provide proper type semantics.

Allow serializers to accept structured hierarchies a la Poison.

This is the natural conclusion of allowing collections. Take for example,

defmodule Person do
  defstruct ~w(name)a
end

defmodule PersonSerializer do
  use Blazon.Serializable

  field name, :string

  field gender, :boolean, via: fn (person) ->
    if String.contains?("John")
      :male
    else
      :female
    end
  end
end

We could serialize a list of people by doing:

iex(1)> Blazon.map([PersonSerializer], [%Person{name: "John Doe"}, %Person{name: "Jane Doe"}])
[%{name: "John Doe", gender: :male}, %{name: "Jane Doe", gender: :female}]

...but what if we want to handle paginated results?

iex(2)> [%Person{name: "John Doe"}, %Person{name: "Jane Doe"}];
nil
iex(3)> Blazon.map(%{page: :integer, per_page: :integer, ..., results: [PeopleSerializer]}, %{page: 1, per_page: 100, ..., results: people})
%{page: 1, per_page: 100, ..., [%{name: "John Doe", gender: :male}, %{name: "Jane Doe", gender: :female}]}

We end up with semantics akin to Poison. This allows for creative composition of serializers that promotes overall understandability and reuse. For example, we could refactor that paginated serialization into:

def paginated(type_or_serializer, results \\ :results) do
  %{page: :integer, per_page: :integer, ..., results => [type_or_serializer]}
end

Blazon.map(paginated(PeopleSerializer, :people), [people])

Move to protocols?

Not even viewer-dependent serialization should require more than one serializer per type. Moving to protocols vastly simplifies the codebase, and should improve performance.

Can we provide a fallback mechanism for tertiary serializers?

Allow deserialization?

Being able to re-use your serializers (that perform type checking) is... bloody useful.

Provide comprehensive serializers for Timex types.

We should expose options that allow for different on-the-wire formatting.

This will require a hand-implementation of the protocol or Blazon.Serializable semantics. Which implies (potentially) a stabilized "standard" for semantics if we don't decide to use protocols.

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.