You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+59-7Lines changed: 59 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -88,28 +88,73 @@ For fine grained control you can create a custom Puget printer, and supply it to
88
88
89
89
For more advanced uses like incorporating diffs into your own Fipp documents, see `lambdaisland.deep-diff2.printer/format-doc`, `lambdaisland.deep-diff2.printer/print-doc`.
90
90
91
-
You can register print handlers for new types using
92
-
`lambdaisland.deep-diff2.printer/register-print-handler!`, or by passing and
91
+
### Print handlers for custom or built-in types
92
+
93
+
In recent versions deep-diff2 initializes its internal copy of Puget with
94
+
`{:print-fallback :print}`, meaning it will fall back to using the system
95
+
printer, which you can extend by extending the `print-method` multimethod.
96
+
97
+
This also means that we automatically pick up additional handlers installed by
98
+
libraries, such as [time-literals](https://github.com/henryw374/time-literals).
99
+
100
+
You can also register print handlers for deep-diff2 specifically by using
101
+
`lambdaisland.deep-diff2.printer-impl/register-print-handler!`, or by passing an
93
102
`:extra-handlers` map to `printer`.
94
103
95
-
Note: the default printer is initialized as `(ddiff/printer {:print-fallback :print})` so that it will fall back to system printer when there is no match.
104
+
If you are dealing with printing of custom types you might find that there are
105
+
multiple print implementations you need to keep up-to-date, see
106
+
[lambdaisland.data-printers](https://github.com/lambdaisland/data-printers) for
107
+
a high-level API that can work with all the commonly used print implementations.
108
+
109
+
#### Example of a custom type
110
+
111
+
See [repl_sessions/custom_type.clj](repl_sessions/custom_type.clj) for the full
112
+
code and results.
113
+
114
+
```clj
115
+
(deftypeDegrees [amount unit]
116
+
Object
117
+
(equals [this that]
118
+
(and (instance? Degrees that)
119
+
(= amount (.-amount that))
120
+
(= unit (.-unit that)))))
121
+
122
+
;; Using system handler fallback
123
+
(defmethodprint-methodDegrees [degrees out]
124
+
(.write out (str (.-amount degrees) "°" (.-unit degrees))))
0 commit comments