npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ddm

v0.1.3

Published

Domain Double Model

Downloads

2

Readme

Domain Double Model

Build Status Test Coverage Code Climate

A simple library for Front-End to create Bounded Context Model.

Install

Bower:

bower install ddm

NPM:

npm install ddm

Usage

Usage:

var ddm = new DDM();

originObject = {
  title: 'hello',
  blog: 'fdsf asdf fadsf ',
  author: 'phodal'
};
var newObject = {};

Basic Example:

ddm.get(['title']).from(originObject).to(newObject);

Result

{title: "hello"}

With Remove:

ddm.get(['title', 'blog', 'author'])
  .from(originObject)
  .remove('title')
  .to(newObject);

Result:

{blog: "fdsf asdf fadsf ", author: "phodal"}

With Add:

ddm.get(['title'])
  .from(originObject)
  .add('tag', 'hello,world,linux')
  .to(newObject);

Result:

{tag: "hello,world,linux", title: "hello"}

With Custom Handle:

function handler(blog) {
  return blog[0];
}

ddm.get(['title', 'blog', 'author'])
  .from(originObject)
  .handle("blog", handler)
  .to(newObject);

Result:

{title: "hello", blog: "A", author: "phodal"}

With Replace:

 ddm.get(['title', 'blog', 'author'])
   .from(originObject)
   .replace("blog", "description")
   .to(newObject);

Result:

{description: "fdsf asdf fadsf ", title: "hello", author: "phodal"}

DDM

对于我们的几个不同业务情景下,我们只使用同一个后台API的情形。如下图所示:

Domain Double Model

在我们的Blog Model里,我们有AuthorTitleSlugContentData几个字段。

而在我们使用的时候,我们需要依据这个模型应用到不同的场景下:

  • 面向读者的Model,只有TagTitleAuthorDateContent五个字段。
  • 面向SEO时,只有TagTitleDate、基于ContentDescription四个字段。
  • 面向RSS时,则有TitleAuthorDateContentSlug五个字段。

如果我们使用的是同一个模型,那么我们就很难做到分离上下文。并且在三种不同的场景下,Blog Model的含义都是不一样的。

于是,我们就需要想办法去区分不同的模型——这在后台来说是一件很容易的事。但是在前台谁想这样做?在这其中使用复杂的OO思想?

所以,我们有了DDM。

License

Phodal's Idea

© 2016 Phodal Huang. This code is distributed under the MIT License. See LICENSE in this directory.

待我代码编成,娶你为妻可好