Methods

โ—๏ธinfo

Here all methods of the Agile Instance are described.

createState()#

Creates a new State, which gets automatically bound to the Agile Instance it was created from.

const State = App.createState('jeff', {
key: 'dummyState',
})

๐Ÿ“ญ Props#

PropTypeDefaultDescriptionRequired
initialValueValueType = anyundefinedInitial Value of StateYes
configStateConfigInterface{}ConfigurationNo

๐Ÿ“„ Return#

Returns a fresh State.




createCollection()#

Creates a new Collection, which gets automatically bound to the Agile Instance it was created from.

const Collection = App.createCollection({
key: 'dummyCollection',
groups: ['myGroup']
})
// or
const Collection2 = App.createCollection((collection) => ({
key: 'dummyCollection',
groups: {
myGroup: collection.Group(['item1', 'item2'])
}
}))

๐Ÿ“ญ Props#

PropTypeDefaultDescriptionRequired
configCollectionConfig{}ConfigurationNo

๐Ÿ“„ Return#

Returns a fresh Collection.




createComputed()#

Creates a new Computed, which gets automatically bound to the Agile Instance it was created from.

const Computed = App.createComputed(() => {/* Computed Method */}, [/* hard coded deps */])
// or
const ComputedWithConfig = App.createComputed(() => {/* Computed Method */}, {
key: 'dummyComputed',
}, [/* hard coded deps */])

๐Ÿ“ญ Props#

PropTypeDefaultDescriptionRequired
computeFunction() => ComputedValueTypeundefinedFunction that recomputes the value of the ComputedYes
configStateConfigInterface{}ConfigurationNo
depsArray<Observer | State | Event | Group>[]Dependencies of ComputedNo

๐Ÿ“„ Return#

Returns a fresh Computed.




createEvent()#

Creates a new Event, which gets automatically bound to the Agile Instance it was created from.

const Event = App.createEvent({
key: 'dummyEvent',
})

๐Ÿ“ญ Props#

PropTypeDefaultDescriptionRequired
configCreateEventConfig{}ConfigurationNo

๐Ÿ“„ Return#

Returns a fresh Event.




integrate()#

Allows us to integrate AgileTs into nearly any Framework/Integration. For instance in case of React, AgileTs offers a React Integration, which allows us to integrate it into AgileTs.

const reactIntegration = new Integration<typeof React, AgileReactComponent>({
key: 'react',
frameworkInstance: React,
bind() {
// Nothing to bind ;D
return Promise.resolve(true);
},
updateMethod(componentInstance, updatedData: Object) {
// Merge changes into State if some Data updated otherwise force rerender
if (Object.keys(updatedData).length !== 0) {
componentInstance.agileProps = flatMerge(
componentInstance.agileProps,
updatedData
);
componentInstance.setState(
flatMerge(componentInstance.state, updatedData)
);
} else {
componentInstance.forceUpdate();
}
},
});
// Each initialIntegraion gets integrated into AgileTs automatically during initialation
// Note: Only useful if you create your own integration
Agile.initialIntegrations.push(reactIntegration);
// Or we integrate it manually (mostly the case if the auto integration doesn't work)
App.integrate(reactIntegration);

๐Ÿ“ญ Props#

PropTypeDefaultDescriptionRequired
integrationIntegrationundefinedIntegration that gets registered/integrated into AgileTsYes

๐Ÿ“„ Return#

Returns the Agile Instance it was called from




hasIntegration()#

Checks if AgileTs has any registered Integration.

๐Ÿ“„ Return#

boolean




createStorage()#

Creates a new Storage.

const Storage = App.createStorage({
key: 'dummyStorage',
methods: {
get: (key: string) => {},
set: (key: string, value: any) => {},
remove: (key: string) => {}
}
})

To register a newly created Storage, we use the registerStorage function.

๐Ÿ“ญ Props#

PropTypeDefaultDescriptionRequired
keystringundefinedKey/Name of StorageYes
methodsStorageMethodsInterface{}Methods with which the Storage get mutatedYes

๐Ÿ“„ Return#

Returns a fresh Storage.




registerStorage()#

Adds a new Storage to AgileTs, which later can store persisted Instances (.persist()). The Local Storage is registered by default.

// Here we create our Storage
const _localStorage = new Storage({
key: 'localStorage',
async: false,
methods: {
get: localStorage.getItem.bind(localStorage),
set: localStorage.setItem.bind(localStorage),
remove: localStorage.removeItem.bind(localStorage),
},
});
// Here we register our Storage
App.register(_localStorage, { default: true });

๐Ÿ“ญ Props#

PropTypeDefaultDescriptionRequired
integrationIntegrationundefinedIntegration that gets registered/integrated into AgileTsYes

๐Ÿ“„ Return#

Returns the Agile Instance it was called from




hasStorage()#

Checks if AgileTs has any registered Storage. If AgileTs couldn't find any Storage, we aren't able to use the .persist() functionality in any Agile Sub Instance.

๐Ÿ“„ Return#

boolean

Last updated on