Skip to content

Instantly share code, notes, and snippets.

@zaaack
Last active July 14, 2017 01:07
Show Gist options
  • Save zaaack/4270c23dcbeef305b236ae3c930db213 to your computer and use it in GitHub Desktop.
Save zaaack/4270c23dcbeef305b236ae3c930db213 to your computer and use it in GitHub Desktop.
import { Struct } from 'immuter'
const struct = Struct({
title: {
zh: '哈利·波特与魔法石',
en: 'Harry Potter and the Philosopher\'s Stone',
},
author: 'J. k. rowling',
tags: ['novel', 'magic'],
})
const struct1 = Struct.clone(struct) // Copy struct, but only modified part will change
struct1.author = 'New Author'
struct1.title.en = 'New Title'
struct1 === struct // false
struct1.author === struct.author // false
struct1.title === struct.title // false
struct1.tags === struct.tags // true
Struct.isStruct(struct) // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment