Commit Graph

18 Commits

Author SHA1 Message Date
Valentin Shergin e05acf1930 Fabric: Managing an EventHandler as a unique_pointer
Summary:
I realized that instead of using shared_ptr's type-erasure feature, we can make the EventHandler's destructor virtual and this itself will allow safe deallocation by a pointer to a base class.
We cannot use the same technic for EventTarget thought because having a weak_ptr to this is another feature of shared_ptr that we need.

Reviewed By: mdvacca

Differential Revision: D9775742

fbshipit-source-id: 3c23a163827e8aa9ec731c89ce87051a93afe4ca
2018-09-13 23:02:37 -07:00
Valentin Shergin 93dd790cad Fabric: Simplified relationship between RawEvent and EventEmitter
Summary: Instead of relying on explicit `RawEventDispatchable` function, we simply check the existence of the `weak_ptr` to `EventTarget`. This is efficient and sufficient because only an EventEmitter retains an associated EventTarget.

Reviewed By: mdvacca

Differential Revision: D9764858

fbshipit-source-id: 4ac25d925f189d0f8b9002e52388fd51629934a8
2018-09-13 23:02:37 -07:00
Valentin Shergin b6e42517e5 Fabric: Now `EventEmitter::setEnabled()` relies on stored `eventTarget` is not being nullptr
Summary:
This diff implements a new model of managing `enabled` flag in EventEmitter.
Now we simply rely on `eventTarget_` is not being `nullptr` (and we reset the pointer to "disable" the event emitter).

Reviewed By: mdvacca

Differential Revision: D9764857

fbshipit-source-id: 1dd3ce0c8589048babbf2dbac9f8359358b31a34
2018-09-13 23:02:37 -07:00
Valentin Shergin c25d5948a5 Fabric: Exposing EventEmitter's ownership model as a shared_ptr
Summary:
As we did in the previous diff, here we implemented `EventEmitter`'s ownership model as a `shared_ptr`. This change fixes problem with leaking `WeakObject`s which happens on hot-reload.

So, in short:
 * `EventTargetWrapper` object owns `jsi::WeakObject` that can be converted to actual `jsi::Object` that represent event target in JavaScript realm;
 * `EventTargetWrapper` and `jsi::WeakObject` objects must be deallocated as soon as native part does not need them anymore;
 * `EventEmitter` objects retain `EventTarget` objects;
 * `EventEmitter` can loose event target object in case if assosiated `ShadowNode` got unmounted (not deallocated); in this case `EventEmitter` is loosing possibility to dispatch event even if some mounting-layer code is still retaining it.

Reviewed By: mdvacca

Differential Revision: D9762755

fbshipit-source-id: 96e989767a32914db9f4627fce51b044c71f257a
2018-09-13 23:02:37 -07:00
Valentin Shergin a089df3f8b Fabric: JSIReleaseFabricEventHandler was replaced with shared_ptr approach
Summary:
Previously, we used special JSI bindings method to release an event handler (`JSIReleaseFabricEventHandler`). Now we expose this ownership model as a regular `std::shared_ptr`, so when the owner got deallocated, the event handler will be released automatically.

Why not use `unique_ptr`? `unique_ptr` is faster (and simpler) indeed, but it does not provide `type erasure` functionality that we need; to use `unique_ptr` we would have to make JSI an explicit Fabric dependency (we will probably end up with it eventually, but I this particular case is not a good reason for that).
All interactions with `eventHandler_` are done in a non-owning manner, so it's as performant as unique_ptr anyway.

(Please ignore all changes in JSCFabricUIManager.h/cpp files, we will delete them soon.)

Reviewed By: mdvacca

Differential Revision: D9756732

fbshipit-source-id: bffdee0c724dc95855ced7c35e7c13cf1554796e
2018-09-13 23:02:36 -07:00
Scott Rice 686ff70d96 Fixup references to old flag_defs.bzl in xplat/
Summary:
The source of truth has already moved, so now we just need to fix references

This diff is mostly the result of running:

```
$ tools/mobile-unification/loadmod --fixup xplat/configurations/buck/apple/flag_defs.bzl tools/build_defs/apple/
```

Then I committed with `hg commit -I xplat/`

The controller you requested could not be found.

Differential Revision: D9772194

fbshipit-source-id: 93d23ae8e1c62440c7876cad965d963bde960db9
2018-09-11 18:47:30 -07:00
Héctor Ramos 1151c096da Update copyright headers to yearless format
Summary: This change drops the year from the copyright headers and the LICENSE file.

Reviewed By: yungsters

Differential Revision: D9727774

fbshipit-source-id: df4fc1e4390733fe774b1a160dd41b4a3d83302a
2018-09-11 15:33:07 -07:00
Valentin Shergin 9570d7d490 Fabric: Unifying usage of `auto`s
Summary:
I was watching a classic magnificent talk about modern C++ by Herb Sutter and I was totally sold on double down on using `auto` in our codebase. Surprisingly, 95% of the code base already follows Herb's guidence; I just changed the last 5% to make it consistent.
All those changes must work *exactly* like it was before.
The talk: https://youtu.be/xnqTKD8uD64?t=28m25s

Reviewed By: mdvacca

Differential Revision: D9753301

fbshipit-source-id: 9629aa485a5d6e51806cc96306c297284d4f90b8
2018-09-10 16:50:02 -07:00
Taras Tsugrii a8a63b1560 Remove unused loads from build files.
Summary: Unused loads hurt readability and take time to process.

Reviewed By: hramos

Differential Revision: D9494120

fbshipit-source-id: 455b56efadab1cb976344cffcb427772bfda2f71
2018-08-31 18:03:07 -07:00
Jonathan Kim 087e2a89fc Clean up xplat relative loads
Reviewed By: scottrice

Differential Revision: D9584163

fbshipit-source-id: 4793b7fa6151c2ec2f8c7fae6271635c9844a50a
2018-08-30 13:04:50 -07:00
Jonathan Kim 2515e4861a Move RN's DEFS.bzl to tools and rename to rn_defs.bzl
Reviewed By: mzlee

Differential Revision: D9553765

fbshipit-source-id: cb65081668ea2726f24d2c9c02661e859cc7a994
2018-08-29 13:21:52 -07:00
Valentin Shergin b49c8add15 Fabric: Rethinking of EventEmitter's role
Summary:
@public
Now, one of the main purposes of `EventEmitter`s is to create RawEvent instances for all specific event invocations.

Reviewed By: mdvacca

Differential Revision: D8886226

fbshipit-source-id: 82a489174efcda097887e70650a2038dc986d149
2018-08-27 07:32:37 -07:00
Valentin Shergin 0dae893eec Fabric: Rethinking of `EventDispatcher`
Summary:
@public
Now, it's not just an abstract class, it's a regular class which unifies event delivery priorities using specific event beats and event pipe.

Reviewed By: mdvacca

Differential Revision: D8886232

fbshipit-source-id: c4360511e5fd477ca7407fc3ebbd99ca578e79cc
2018-08-27 07:32:37 -07:00
Valentin Shergin b784adc7ae Fabric: `FabricUIManager::dispatchEventToEmptyTarget` got coupled with `dispatchEventToTarget`
Summary:
@public
Instead of having two methods it's easier to have just one which can be abstracted as `EventPipe`.

Reviewed By: mdvacca

Differential Revision: D8886231

fbshipit-source-id: af9fd92dc4afa1219a11acce0aa021a85c94d232
2018-08-27 07:32:35 -07:00
Valentin Shergin 5965ba283f Fabric: Introducting EventQueue (+ Batched and Unbatched versions)
Summary:
@public
EventQueue is a queue of events that synchronizing event dispatching with given Event Beat.
The only difference between UnbatchedEventQueue and BatchedEventQueue is that UnbatchedEventQueue `induce` an Event Beat right after enqueing an event.

Reviewed By: mdvacca

Differential Revision: D8886225

fbshipit-source-id: fedba6fdff2ecb6f3c615cea09b5fdaa58890479
2018-08-27 07:32:35 -07:00
Valentin Shergin 504c7694c4 Fabric: Introducing `RawEvent`
Summary:
@public
RawEvent represents ready-to-dispatch event data, an event that can be processed uniformly.

Reviewed By: mdvacca

Differential Revision: D8886235

fbshipit-source-id: 1c905517814330c5ecbf39f0ebc95ff2b576d1f2
2018-08-27 07:32:35 -07:00
Valentin Shergin 57bbce9bd9 Fabric: Introducing EventBeat concept (and MainRunLoopEventBeat)
Summary:
@public
EventBeat is an abstraction around proper event scheduling combining proper timing and proper threading. Event Queues use Event Beat to ensure that events are delivered on proper threads and in proper timing (probably batched). Consumers can `request` the next beat and `induce` immediatly beat.
MainRunLoopEventBeat implements particular Event Beat synchronized with the main event loop and calling a callback on the main thread.

Reviewed By: mdvacca

Differential Revision: D8886229

fbshipit-source-id: 1a42fcbf4cd61c6cb4c502890566c98b00226f31
2018-08-27 07:32:34 -07:00
Valentin Shergin 07a4a959a7 Fabric: Events related classes were moved to separate buck target
Summary:
@public
We need that because gonna add much more event-related stuff, so it deserves separate buck target.

Reviewed By: mdvacca

Differential Revision: D8831547

fbshipit-source-id: 616581b39b425a49302d5f7f86267e62b0d58389
2018-07-17 22:53:57 -07:00