Script authors: changes to the repositories API

Discussion for the unofficial, community-developed addons, extensions and scripts built for the Waze Map Editor.

The official index of these tools is the Community Plugins, Extensions and Tools wiki page.

Moderators: Unholy, bextein, JustinS83, Glodenox

Forum rules
Discussion for the unofficial, community-developed addons, extensions and scripts built for the Waze Map Editor.

DO NOT START a new thread unless it is about a new idea. Keep discussion of existing tools within the main thread for that tool.

The official index of these tools is the Community Plugins, Extensions and Tools wiki page.

Script authors: changes to the repositories API

Postby Glodenox » Tue Jul 31, 2018 2:30 pm

Hey everyone,

With today's release of the Waze Map Editor the methods available for repositories such as the segments, streets and users have been adjusted slightly. Whereas previously you could get an object with the .get() method (example: W.model.streets.get(someStreetId);), you now need to use .getObjectById() instead.

At the moment, .get() is still available as a proxy to the new .getObjectById() method, but it will be removed in an upcoming release of the WME (no fixed date, depends slightly on how many scripts would become broken at that point). Whenever a script currently uses .get(), a notification message will be logged in the web console of your browser. Therefore it is advised to update your userscripts in the following weeks. The change is minimal, but here's an example to help you out:
Code: Select all
W.model.users.get(267294555);

Should be replaced with
Code: Select all
W.model.users.getObjectById(267294555);

The same applies for all these repositories under W.model:
segments, nodes, users, streets, cities, states, countries, problems, mapUpdateRequests, venues, junctions, bigJunctions, roadClosures, cameras, userAreas, problemDetails, houseNumbers, updateRequestSessions, archives, archiveSessions, managedAreas, majorTrafficEvents, restrictedAreas and mapComments.

I've gone through the userscripts known to the Discord !script command and found these userscripts to be affected by this:
Code: Select all
WME Advanced Closures
WME Bookmarks
WME ClickSaver
WME Closure Details
WME Color Speeds
WME Form Filler
WME Junction Angle Info
WME MagicWand
WME Map Tiles Update
WME PL Jump
WME Place Harmonizer
WME Place Interface Enhancements
WME PlaceNames
WME RA Util
WME Reverse Nodes
WME Road History
WME Road Selector
WME Route Checker
WME Route Speeds (MoM fork)
WME Select Same Type Roads
WME Show Alt Names
WME Speedlimits
WME Street to River PLUS
WME UR Comments
WME UR-MP Tracking
WME Validator

Overview spreadsheet of affected scripts

FYI: there may also still be some calls to the get() function within the vanilla WME code though. They should mostly be gone, but I've found at least one such call already (when selecting a segment with a road closure). So don't necessarily think any such messages are always caused by your own scripts. Usually that will be the case though ;)

Thanks for all your awesome work!
Last edited by Glodenox on Tue Jul 31, 2018 4:10 pm, edited 1 time in total.
Script Writing Community Coordinator
[ img ][ img ]
Glodenox
Waze Global Champs
Waze Global Champs
 
Posts: 1009
Joined: Tue Aug 11, 2015 9:04 pm
Location: Belgium
Has thanked: 480 times
Been thanked: 1167 times

Re: Script authors: changes to the repositories API

Postby MapOMatic » Tue Jul 31, 2018 3:57 pm

Thanks, Glodenox. In addition, the W.model.actionManager.actions property was removed in the latest WME release. References to that can be replaced with the W.model.actionManager.getActions() function.
[ img ] [ img ]

AM Central KY | CM USA
MapOMatic
Country Manager
Country Manager
 
Posts: 340
Joined: Sat Jul 16, 2011 11:43 am
Location: Lexington, KY
Has thanked: 227 times
Been thanked: 635 times

Re: Script authors: changes to the repositories API

Postby Glodenox » Tue Jul 31, 2018 7:30 pm

I also just noticed there hasn't been an announcement yet about the repositories that weren't affected by the changes above: the get() function there is being replaced with getAsync().

Here's a direct quote of what has changed:
W.model.problemDetails.get() was renamed to W.model.problemDetails.getAsync()
W.model.houseNumbers.get() was renamed to W.model.houseNumbers.getAsync()
W.model.updateRequestSessions.get() was renamed to W.model.updateRequestSessions.getAsync()
W.model.archives.get() was renamed to W.model.archives.getAsync()
W.model.archiveSessions.get() was renamed to W.model.archiveSessions.getAsync()

If anyone uses these functions, you can't just swap out "get" with "getAsync". As the name implies, these functions now return a Promise object, which will be resolved at a later point in time. Here's an example of how you'd usually handle promises:
Code: Select all
W.model.problemDetails.getAsync(['2/5606837'])
    .then((details) => console.log(details))
    .catch((error) => console.log(error));

Be aware that any lines you place outside of the callback function you put in then will be executed immediately after executing that line. This means that your code isn't stuck when it tries to retrieve this sort of data, but at the same time it also means you might need to adjust your code so it can deal with some information not being available yet.

Please note that I'm using the arrow function expression in that example to create a function somewhat comparable to an anonymous function. You could also use function(details) { console.log(details); } as before if you really want to.
Script Writing Community Coordinator
[ img ][ img ]
Glodenox
Waze Global Champs
Waze Global Champs
 
Posts: 1009
Joined: Tue Aug 11, 2015 9:04 pm
Location: Belgium
Has thanked: 480 times
Been thanked: 1167 times

Re: Script authors: changes to the repositories API

Postby JustinS83 » Tue Jul 31, 2018 7:54 pm

Glodenox wrote:I also just noticed there hasn't been an announcement yet about the repositories that weren't affected by the changes above: the get() function there is being replaced with getAsync().

Here's a direct quote of what has changed:
W.model.problemDetails.get() was renamed to W.model.problemDetails.getAsync()
W.model.houseNumbers.get() was renamed to W.model.houseNumbers.getAsync()
W.model.updateRequestSessions.get() was renamed to W.model.updateRequestSessions.getAsync()
W.model.archives.get() was renamed to W.model.archives.getAsync()
W.model.archiveSessions.get() was renamed to W.model.archiveSessions.getAsync()

If anyone uses these functions, you can't just swap out "get" with "getAsync". As the name implies, these functions now return a Promise object, which will be resolved at a later point in time. Here's an example of how you'd usually handle promises:
Code: Select all
W.model.problemDetails.getAsync(['2/5606837'])
    .then((details) => console.log(details))
    .catch((error) => console.log(error));

Be aware that any lines you place outside of the callback function you put in then will be executed immediately after executing that line. This means that your code isn't stuck when it tries to retrieve this sort of data, but at the same time it also means you might need to adjust your code so it can deal with some information not being available yet.

Please note that I'm using the arrow function expression in that example to create a function somewhat comparable to an anonymous function. You could also use function(details) { console.log(details); } as before if you really want to.


Alternatively, if you want it to act synchronous you can use async await, which I would recommend. Read the linked article but basically you can do something like this:
Code: Select all
async function doStuff(){
    var result = await W.model.problemDetails.getAsync(['2/5606837']);
    if(result != null)
        doMoreStuff();
    else
        StuffIsBroken();
}
Script Writing Community Coordinator
[ img ][ img ][ img ][ img ][ img ]
JustinS83
Waze Global Champs
Waze Global Champs
 
Posts: 1313
Joined: Wed Dec 03, 2014 4:33 am
Location: Franklin, OH
Has thanked: 335 times
Been thanked: 2332 times

Re: Script authors: changes to the repositories API

Postby crazycaveman » Fri Aug 03, 2018 12:39 pm

Surprised WAL escaped the list, definitely has some references to .get() I need to clean up...
[ img ][ img ] [ img ][ img ][ img ]
ARC: South Atlantic Region
crazycaveman
US Waze Champs
US Waze Champs
 
Posts: 826
Joined: Fri Sep 03, 2010 1:48 am
Location: Rock Hill, SC, USA
Has thanked: 351 times
Been thanked: 512 times


Return to Addons, Extensions, and Scripts

Who is online

Users browsing this forum: whathappened15