2.0.2 • Published 6 years ago

rx-thunk-subject v2.0.2

Weekly downloads
1
License
MIT
Repository
-
Last release
6 years ago

rx-thunk-subject

An rx subject from an async thunk.

  • The thunk is not executed until the first subscription is done
  • The value can be invalidated thus refreshing existing subscribers values
  • Useful for managing changing values from the server
  • Subscribers only need to manage sync values

Create a ThunkSubject from an async thunk

async function query() : Promise<Data> {
    return fetch("/api/myquery");
}

//The query function will not be executed until the first subscribe call
const data = new ThunkSubject(query);

Subscribe to your data

function handleData(value: Data) {
    //handle your data.
}

//The query function is called, handleData gets the query promise
data.subscribe(handleData)

...
//Other handler receives the last thunk value, the query function is not called
data.subscribe(otherHandler);

Refresh your data

//The query function is called if there are any subscribers, all subscribers get the new value
//If there isn't any subscribers, the function is called on the next subscription
data.invalidate();
2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.0

7 years ago