nitrogen 'me', anchor and target

49 views
Skip to first unread message

Dmitriy Kargapolov

unread,
Oct 23, 2012, 8:28:11 PM10/23/12
to nitro...@googlegroups.com
Hi All,
Nitrogen.$anchor(Anchor, Target) is used to set $anchor_path and $target_path for current context. It called, for example, when wf:wire/2 invoked for some element.
The docs mentioned "me" nitrogen selector which is set to current anchor and assumed to point to the element. But after calling wf:wire/2 (and subsequent Nitrogen.$anchor(Anchor, Target)) element path is saved in $target_path, not in $anchor_path. This make unusable "me" selector, which keeps 'page' reference but not the element...
At the same time I grep-ed for $target_path through the nitrogen code and didn't find any use of it.
Shouldn't be 'me' selector meaning revised? Or, otherwise, might be wf:wire/2 should set anchor to the element given, not to the 'page'?
Thanks.

Jesse Gumm

unread,
Oct 23, 2012, 11:54:54 PM10/23/12
to nitro...@googlegroups.com
Hi Dmitriy,

I'm not seeing any of this behavior. Calling wf:wire/2 will set both
the target_path and the anchor_paths to the provided Target (since
wf:wire(Target, Action) is the same as wf:wire(Target, Target,
Action).

Could you provide a sample module of this behavior in action?

-Jesse
> --
> You received this message because you are subscribed to the Google Groups
> "Nitrogen Project / The Nitrogen Web Framework for Erlang" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/nitrogenweb/-/WZ16EgYzZGYJ.
> To post to this group, send email to nitro...@googlegroups.com.
> To unsubscribe from this group, send email to
> nitrogenweb...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/nitrogenweb?hl=en.



--
Jesse Gumm
Owner, Sigma Star Systems
414.940.4866 || sigma-star.com || @jessegumm

Dmitriy Kargapolov

unread,
Oct 24, 2012, 12:34:05 AM10/24/12
to nitro...@googlegroups.com, gu...@sigma-star.com
Jesse,
wf:wire(Target, Action) calls wf:wire(Target, Target, Action) substituting 1st Trigger element. (this is confusing btw).
Then later calls action_wire:fire/3, where Achor is set from wf_context:anchor(), not from any arguments.

My code tests simple comet:

body() ->
...
    wf:comet(fun update_time/0),
...

update_time() ->
    timer:sleep(1000),
    {{_, _, D}, {H, M, S}} = calendar:local_time(),
    Time = lists:concat([D, "/", H, ":", M, ":", S]),
    Script = wf:f("objs('##timeStamp>span>span').text('~s');", [Time]),
    wf:wire(timeStamp, Script),
    wf:flush(),
    update_time().

Where I assume I could use 'me' instead of '##timeStamp', because Script used in context of timeStamp element in wf:wire/2 call. At least I'd like to think so. In practice 'me' translated to 'page' anchor...

(ugly '>span>span' is a temp workaround for jQuery button-link text update)

Jesse Gumm

unread,
Oct 24, 2012, 2:47:40 AM10/24/12
to nitro...@googlegroups.com
I see. You're right, I confused even myself with my explanation of
wf:wire/2. Neither of the first two args of wf:wire/3 are Anchor.
It's Trigger and Target. Anchor is the element from which the action
is called.

And as you say, the anchor is retrieved from the context (which in
comet, being it's own process, has its own context).

You *could* set the anchor of the comet process with
wf_context:anchor(timeStamp), then any uses of 'me' called from the
comet process should point where you expect them to point.

I definitely see why this is confusing, and I'm not sure the best
solution for this. As you mentioned, $target_path does not seem to be
used anywhere, so there's an obvious candidate for a solution of some
sort. This is definitely something I'm willing to explore further.

Thanks,

-Jesse


On Tue, Oct 23, 2012 at 11:34 PM, Dmitriy Kargapolov
> https://groups.google.com/d/msg/nitrogenweb/-/jbvMnT3C-sAJ.

Dmitriy Kargapolov

unread,
Oct 24, 2012, 9:07:01 AM10/24/12
to nitro...@googlegroups.com, gu...@sigma-star.com
One way to solve this would be:

- leave 'me' as it is, for compatibility, but mark it as deprecated
- add new selector, which unambiguously substituted with $target_path
- add one more selector, for $anchor_path
- use new selectors instead of 'me' over the Nitrogen code

Names might be '##target' or '##element' or '##self' and '##anchor', for example.

Thank you.
Reply all
Reply to author
Forward
0 new messages