[Pharo-users] Setting a model for a Spec UI in Pharo 8

Bren asparagi at hhhh.org
Wed Feb 12 17:26:48 EST 2020

Hi fellow Pharo folks,

TL;DR: The only apparent way to open a standalone presenter on a user-specified model, SpPresenter>>on:, has a comment suggesting it will be deprecated.

As a follow-up to my previous question in case someone DuckDuckGoes it in the future, it seems that adding self modelChanged to SpPresenterWithModel>>setAnnouncingObject: breaks the Spec2 demos.  So, I backed my fix out of my image.  This has several implications:

- To actually change an SpPresenterWithModel's model, one must send model: and then modelChanged.  This seems to break encapsulation.
- The Spec2 demos seem to rely on modelChanged not arriving before the UI opens.  This seems fragile, and reduces the utility of using the demos as examples for writing non-demo code.
- Since I can't send modelChanged from model:, I must apparently use SpPresenter>>on: to open a standalone instance of my subclass of SpPresenterWithModel on a model I supply (e.g. (BLFunctionPresenter on: aModel) openWithSpec).  I was avoiding this because unfortunately, the comment foreshadows deprecation but does not explain what to use instead.  I do not understand how a subclass of SpPresenterWithModel can be composable after this deprecation. 

So, I have a solution for now, but I am still looking for the supported way to open a standalone presenter on a user-specified model.


> On Feb 8, 2020, at 3:22 PM, Bren <asparagi at hhhh.org> wrote:
> Hi Pharo friends,
> TL;DR: How should one open a presenter on a user-specified model?  Is SpPresenterWithModel>>setAnnouncingObject: missing a call to modelChanged?
> The long version:
> I am trying to write a UI for my threat modeling tool using Spec in Pharo 8.  I had trouble getting my first presenter to show me my model.  My current VERY WIP tiny code is available from git at github.com:octotrike/groundhog.git, on branch pharo-sp-presenter-question.
> I wanted to do something like this (paraphrased from the class comment for my BLFunctionPresenter class):
> BLFunctionPresenter new
>  model: aModel; 
>  openWithSpec
> Unfortunately, the UI continued to show the default announcingObject (nil), even though announcingObject had changed as expected.
> The examples I found showed either
> - a containing presenter getting an event, changing instance variables on a presenter it contains, and sending modelChanged, or
> - a presenter hard coded to show a model that is globally accessible.
> In the end, I added self modelChanged to the end of SpPresenterWithModel>>setAnnouncingObject:.  It seemed like this method changed announcingObject and registered this presenter to receive modelChanged every time changes to the announcingObject occurred.  However, in cases like the one I am describing, the change is replacement of the entire announcingObject, so no announcingObject sends modelChanged.
> Was/is this a bug in Spec?  Or is there something else I should be doing to open a Spec UI on a model that is neither global nor specified by a parent presenter?
> Bren

More information about the Pharo-users mailing list