0.0.2 • Published 3 years ago

vuedo v0.0.2

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

vuedo

useSorter

const sorter = useSorter({
  // default sorting rules
  // name: (x, y, def) => def(x, y)
  // provide custom sorter or for complex data
});
const arr = ref([
  {name: 'name0'},
  {name: 'name1'}
]);
const sorted = sorter.getSorted(arr);
// sorter.key.value & sorter.desc.value - to set sorting

usePromise

const promise = ref(invalidate => {
  return new Promise((res, rej) => {
    invalidate(rej);  // called if promise.value changes before fulfill
    setTimeout(res, 1000);
  });
});
// can be called with Promise / ref<Promise> / ref<PromiseFactoryWithInvalidation>
const promiseState = usePromise(promise);
// promiseState: {
//    pending: ref()
//    fulfilled: ref()
//    finished: ref()
//    rejected: ref()
//    error: ref()
// }

useService

class ServiceFactory {
  field = 'test';
  constructor(field: string) {
    this.field = field;
  }
}
// create ServiceFactory instance
// prodiver called outside component will provide globally
provideService(ServiceFactory);
// create ServiceFactory instance manually
provideService(ServiceFactory, () => new ServiceFactory('test2'));

// to get service instance
useService(ServiceFactory)
0.0.2

3 years ago

0.0.1

3 years ago