Mercurial > repos > tabletprog
annotate modules/jsonEncoder.tp @ 338:1458c069c715
Added "value" method to option value and option none. It behaves similarly to value:none, except the none case just propagates the none value and the value case wraps the result in an option value
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 04 Apr 2015 11:54:46 -0700 |
parents | eef8a5cea812 |
children |
rev | line source |
---|---|
329
eef8a5cea812
Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #{ |
eef8a5cea812
Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 //this module exists to break a circular dependency between the json module |
eef8a5cea812
Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 //and container types like dictionaries |
eef8a5cea812
Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 encode <- :value { |
eef8a5cea812
Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 if: (object does: value understand?: "jsonEncode") { |
eef8a5cea812
Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 value jsonEncode |
eef8a5cea812
Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 } else: { |
eef8a5cea812
Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 toEncode <- #[] |
eef8a5cea812
Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 if: (object does: value understand?: "serializeFields") { |
eef8a5cea812
Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 toEncode <- value serializeFields |
eef8a5cea812
Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 } else: { |
eef8a5cea812
Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 toEncode <- object propertiesOf: value |
eef8a5cea812
Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 } |
eef8a5cea812
Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 parts <- #[] |
eef8a5cea812
Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 foreach: toEncode :idx field { |
eef8a5cea812
Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 fieldVal <- object sendMessage: field to: value |
eef8a5cea812
Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 parts append: (field jsonEncode) . ":" . (encode: fieldVal) |
eef8a5cea812
Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 } |
eef8a5cea812
Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 "{" . (parts join: ",") . "}" |
eef8a5cea812
Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 } |
eef8a5cea812
Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 } |
eef8a5cea812
Use a smarter algorithm for calculating module init order and break some circular module dependencies in the standard library
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 } |