Mercurial > repos > tabletprog
annotate modules/jsonEncoder.tp @ 351:04ba2118c5fe
Rename (dict hash) size to (dict hash) length and make it actually work
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 13 Apr 2015 22:41:00 -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 } |